解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
2008-07-21 18:16
369 查看
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的问题
- 解决User.Identity.IsAuthenticated==false 或User.Identity.Name==string.empty的问题
- target is null for setProperty(null, "username", [Ljava.lang.String;@c06258)问题
- WebService来获取Context.User.Identity.Name为空的问题?
- 添加 <identity impersonate="true" userName="username" password="password"/>,解决问题!
- 添加 <identity impersonate="true" userName="username" password="password"/>,解决问题!
- 集成平台自动登入+C# Login控件,造成的HttpContext.Current.User.Identity.Name 为空问题解决方案
- 复制功能,比较经典的一段程序,IsDBNull()、User.Identity.Name、myReader.GetString()、取得下拉选框的值:DropDownList1.SelectedValue
- string path = FormsAuthentication.GetRedirectUrl(User.Identity.Name, false);
- github使用过程中多账户造成的Permission to repository denied to username问题
- 关于jstl EL用法的注意点(java.lang.NumberFormatException: For input string: "userName")
- ObQueryNameString的一个问题
- asp.net Context.User.Identity.Name说明
- 用java String类的getBytes(String charsetName)和String(byte[] bytes, String charsetName)解决乱码问题
- Analyze 分析内存 检测出现 User-facing text should use localized string macro 警告问题