解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
来源:互联网 发布:网络渗透用什么系统 编辑:程序博客网 时间:2024/06/07 11:32
HttpContext.Current.User.Identity.IsAuthenticated=false;
HttpContext.Current.User.Identity.Name==""
解释:当用户登录时,服务器为确认客户端通过验证要通过cookie向客户端写验证(Authenticat)信息,在登录页面刚验证完成后服务器还没有把cookie 回发到Client,所以会没有值,当服务器第二次Response的时候,就会从客户端读取Cookie,要想有此Cookie还要在web.config文件中配置相应的参数
<system.web>
<authentication mode="Forms">
<forms domain="bokoAdmin" timeout="20" loginUrl="Login.aspx" path="/"></forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<system.web>
程序验证:
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;
另推荐一个繁体的MSDN论坛:http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14
authorization节点解决FormsAuthentication.SignOut(); 不起作用的问题。
- 解决User.Identity.IsAuthenticated=false 或User.Identity.Name=string.empty的问题
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- HttpContext.Current.User.Identity.IsAuthenticated 这个是表示的什么
- Context.User.Identity.Name说明
- Context.User.Identity.Name是什么意思?
- 从identity impersonate="false"谈起
- asp.net Context.User.Identity.Name说明
- 关于FormsAuthentication.RedirectFromLoginPage() context.user.Identity.name
- asp.net Context.User.Identity.Name说明
- User.Identity.Name获取为空解决方法
- 使用User.Identity对象
- HttpContext.Current.User.Identity.Name 有时获取值不成功
- HttpContext.Current.User.Identity.Name获得不了登录名
- ASP.NET自定义身份验证的实践(Page.User.Identity.Name的使用)
- android自定义标题栏
- onInterceptTouchEvent和onTouchEvent调用时序
- Cocos2d-x CocosWidget 项目介绍及说明
- 操作系统意义上的堆和栈的概念以及数据结构意义上的堆和栈的概念
- Sparsity and Some Basics of L1 Regularization
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- 追本溯源 解析“大数据生态环境”发展现状
- Wins服务器删除和逻辑删除记录
- 反向 Ajax,第 1 部分: Comet 简介
- 慎用TCP的选项SO_LINGER
- cocos2d-x中设置颜色
- 【数据结构】 循环单链表 约瑟夫回环问题
- 探索IOS版优酷视频下载
- andriod驱动之旅-在Ubuntu上为Android系统内置Java应用程序测试Application Frameworks层的硬件服务(8)