悬赏园豆:10
[已关闭问题]
<P>我用FormsAuthentication.SetAuthCookie(user,false);创建一个身份验证票.然后用HttpContext.Current.User.Identity.IsAuthenticated 去检测是否通过验证.测试结果HttpContext.Current.User.Identity.IsAuthenticated 有时为true, 有时为flase</P>
<P>但是</P>
<P>用下面的方法创建时</P>
<P>FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, user,DateTime.Now, DateTime.Now.AddMinutes(30), false, null, "/");<BR> string HashTicket = FormsAuthentication.Encrypt(Ticket);<BR> HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);<BR> Context.Response.Cookies.Add(UserCookie);</P>
<P> FormsIdentity identity = new FormsIdentity(Ticket);<BR> GenericPrincipal user = new GenericPrincipal(identity, new string[] {});</P>
<P> HttpContext.Current.User = user;</P>
<P mce_keep="true">HttpContext.Current.User.Identity.IsAuthenticated一直为true.</P>
<P mce_keep="true">web.config中的配置为</P>
<P mce_keep="true"><authentication mode="Forms"> <BR> <forms loginUrl="login.aspx" name="AuthCookie" timeout="60" path="/" defaultUrl="Default.aspx" cookieless="AutoDetect" ><BR> </forms><BR> </authentication></P>
<P mce_keep="true"> </P>
<P mce_keep="true">分析一下这是什么原因? 为什么用FormsAuthentication.SetAuthCookie(user,false) 后,HttpContext.Current.User.Identity.IsAuthenticated还会为false呢?</P>
<P mce_keep="true"> </P>