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 ...
随机推荐
- IAR EWARM Example Download List
https://srv.iar.com/ExamplesOnDemand/versions.xml http://netstorage.iar.com/SuppDB/Public/EXAMPLES/0 ...
- Architecture of Device I/O Drivers, Device Driver Design
http://www.kalinskyassociates.com/Wpaper4.html Architecture of Device I/O Drivers Many embedded syst ...
- 前向否定界定符 python正则表达式不匹配某个字符串 以及无捕获组和命名组(转)
[编辑] 无捕获组和命名组 精心设计的 REs 也许会用很多组,既可以捕获感兴趣的子串,又可以分组和结构化 RE 本身.在复杂的 REs 里,追踪组号变得困难.有两个功能可以对这个问题有所帮助.它们也 ...
- jQuery + jQuery Mobile 实现省市二级下拉列表页面
一.需求: 提供省.市下拉列表,当用户选择省一级下拉列表项后,市下拉列表的各个选项自动变为该省对应的城市列表. 二.效果: 三.实现: 1.省市json数据,来自: http://www.cnblog ...
- SAP Connector 3.0 .Net 开发
在VS2010中使用控制台应用程序使用SAP Connector 3.0开发时,当程序运行到实例化RfcConfigParameters时报错 (RfcConfigParametersrefcon = ...
- Codeforces Round #338 (Div. 2) C. Running Track dp
C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...
- 007_尚学堂_高明鑫_android 之项目的打包apk与apk的反编译
http://www.tudou.com/programs/view/kMQlxff8evM/
- Android上的SQLLite性能分析
也许有人还不知道,Android 是有一些内建的 类库支持 SQL Lite 数据库的操作.他提供了一个很好的方式在 Android 上组织少量的数据.不管怎样,在使用这些类库的时候有一些陷阱是需要注 ...
- Vs2008几个快捷键
CTRL+M 收缩 格式化cs代码:Ctrl+k+f 格式化aspx代码:Ctrl+k+d 5. 怎样快速切换不同的窗口? Ctrl+Tab 7. 怎样快速添加代码段? 输入prop然后按两 ...
- mysql常用知识点
--存储过程及常用流程控制语法 /*该代码是创建了一个名叫"p4"的存储过程并设置了s1,s2,s3两个int型一个varchar型参数,还可以是其他数据类型,内部创建了x1,x2 ...