HttpContext.Current.User.Identity.IsAuthenticated
HttpContext.Current.User.Identity.IsAuthenticated=false;
HttpContext.Current.User.Identity.Name==""
解释:当用户登录时,服务器为确认客户端通过验证要通过cookie向客户端写验证(Authenticat)信息,在登录页面刚验证完成后服务器还没有把cookie 回发到Client,所以会没有值,当服务器第二次Response的时候,就会从客户端读取Cookie,要想有此Cookie还要在web.config文件中配置相应的参数
|
1
2
3
4
5
6
7
8
|
<system.web> <authentication mode="Forms"> <forms domain="bokoAdmin" timeout="20" loginUrl="Login.aspx" path="/"></forms> </authentication><authorization> <allow users="*"/> </authorization><system.web> |
程序验证:
|
1
2
3
4
5
6
7
8
9
10
11
12
|
if (Membership.ValidateUser(tbx_username.Text.TrimEnd(), tbx_password.Text.TrimEnd())) { FormsAuthentication.SetAuthCookie(tbx_username.Text.TrimEnd(), true,FormsAuthentication.FormsCookiePath);FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, tbx_username.Text, DateTime.Now, DateTime.Now.AddMinutes(20), false, tbx_username.Text); // generate new identity FormsIdentity identity = new FormsIdentity(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); // write to client. Response.Cookies.Add(cookie); } |
其中加粗体为主要语句,有此一句就可以实现HttpContext.Current.User.Identity.IsAuthenticated=true;
authorization节点解决FormsAuthentication.SignOut(); 不起作用的问题
HttpContext.Current.User.Identity.IsAuthenticated的更多相关文章
- if (HttpContext.Current.User.Identity.IsAuthenticated) 权限验证总是true
将浏览器关闭重启. 注:该语句是判断用户是否经过验证.
- 【ASP.NET】 HttpContext.Current.User.Identity.Name 返回值为空
问题起因 在做项目的时候,我使用HttpContext.Current.User.Identity.Name来获取Web应用程序正在使用时的用户名. 在开发过程中,我使用了我的本地iis,启用了集成的 ...
- MVC绕过登陆界面验证时HttpContext.Current.User.Identity.Name取值为空问题解决方法
Global.asax界面添加如下方法: void FormsAuthentication_Authenticate(object sender, FormsAuthenticationEventAr ...
- WebApi设置HttpContext.Current.User
1.Web.config配置上system.web节点下加入以下配置 <system.web> <authentication mode="Forms"> ...
- 对于HttpContext.Current的一点理解
string[] userInfomationSplits = HttpContext.Current.User.Identity.Name.Split(new string[] { "\\ ...
- 如何手动让HttpRequestBase.IsAuthenticated 和 HttpContext.User.Identity.IsAuthenticated 为true.
今天为了重写权限验证这块需要重写AuthorizeAttribute 这个属性,看了官方文档:HttpContextBase.User.Identity.IsAuthenticated 这个必须是tr ...
- HttpContext.Current.User is null after installing .NET Framework 4.5
故障原因:从framework4.0到framework4.5的升级过程中,原有的form认证方式发生了变化,所以不再支持User.Identity.Name原有存储模式(基于cookie),要恢复这 ...
- if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思?
if (user?.Identity?.IsAuthenticated ?? false)这几个问号分别都代表啥意思? 0 悬赏园豆:5 [已解决问题] 浏览: 229次 解决于 2018-05-16 ...
- 异步 HttpContext.Current 为空null 另一种解决方法
1.场景 在导入通讯录过程中,把导入的失败.成功的号码数进行统计,然后保存到session中,客户端通过轮询显示状态. 在实现过程中,使用的async调用方法,出现HttpContext.Curren ...
随机推荐
- 一个html5 + nodejs的游戏
可以阅读Mozilla开源的Browser Quest这个项目,一个html5 + nodejs的游戏,完整演示了客户端服务端怎么通讯的,逻辑怎么做的,通讯怎么做的,很值得参考. 游戏demo: ht ...
- RFID Reader 线路图收集
This 125 kHz RFID reader http://www.serasidis.gr/circuits/RFID_reader/125kHz_RFID_reader.htm http:// ...
- PL/pgSQL的anyelement例子
http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html 定义函数 pgsql=# CREA ...
- Mac OS增删环境变量
一.首先查看shell版本 使用命令echo $SHELL 如果输出的是:csh或者是tcsh,就是C Shell.如果输出的是:bash,sh,zsh,就是Bourne Shell的一个变种. Ma ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...
- iOS开发——数据持久化OC篇&plist文件增删改查操作
Plist文件增删查改 主要操作: 1.//获得plist路径 -(NSString*)getPlistPath: 2.//判断沙盒中名为plistname的文件是否存在 -(BOOL ...
- h5-3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- IO 延迟与Queue Depth
IO 延迟:存储设备的IO延迟 Queue Depth:磁盘控制器所发出的批量指令的最大条数 IOPS:磁盘设备每秒的IO 三者之间的关系:IOPS=(Queue Depth)/(IO latenc ...
- Repeater的ItemCreated和ItemDataBind的区别
Repeater 的ItemCreated的事件在第一次调用DataBind方法的时候触发,即在(IsPostBack==false)的时候才调用,当页面回滚是将不是调用该方法(错误的源头).而Ite ...