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 ...
随机推荐
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟
A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You ...
- cdoj 26 遮挡判断(shadow) 水题
遮挡判断(shadow) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/26 ...
- Robot Instructions
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- ibatis 分页的简单实现
ibatis 物理分页的简单实现 cheungmine 2013-8-26 使用SSI (Struts2, Spring3, iBATIS2.3)框架开发Web服务的时候有一个需求就是对查询得到的结果 ...
- [AngularJS] Using Services in Angular Directives
Directives have dependencies too, and you can use dependency injection to provide services for your ...
- swift 3.0基本数据语法
swift 3.0 字符串的介绍 OC和Swift中字符串的区别 在OC中字符串类型时NSString,在Swift中字符串类型是String OC中字符串@"",Swift中字符 ...
- iOS开发——数据持久化Swift篇&(四)CoreData
CoreData import CoreData class ViewController: UIViewController { override func viewDidLoad() { supe ...
- Browser 與 Server 持續同步的作法介紹 (Polling, Comet, Long Polling, WebSocket)长连接
對 Comet 的懵懂 記得兩年多前,第一次看到 Gmail 中的 GTalk 覺得很好奇:「咦?線上聊天且是 Google 的熱門系統,只用傳統的 AJAX 應該會操爆伺服器吧?」很幸運的,當時前公 ...
- javascript 拷贝
拷贝简单分为浅拷贝与深度拷贝,即给定一个对象,生成一个相同的对象. 浅拷贝 function copy(source,destiny){ destiny = destiny || {}; if(typ ...