C# 为什么验证后HttpContext.Current.Request.IsAuthenticated为false
我已经使用表单身份验证在我的网站上创建了登录, 我不明白为什么在创建票据并将其添加到cookies之后 如果我检查HttpContext.Current.Request.IsAuthenticatedC# 为什么验证后HttpContext.Current.Request.IsAuthenticated为false,c#,asp.net,cookies,forms-authentication,C#,Asp.net,Cookies,Forms Authentication,我已经使用表单身份验证在我的网站上创建了登录, 我不明白为什么在创建票据并将其添加到cookies之后 如果我检查HttpContext.Current.Request.IsAuthenticated 我猜错了。只有在后续请求中,用户才能通过身份验证 这是我的密码 var fat = new FormsAuthenticationTicket( 1, username, DateTime.Now, DateTime.Now.AddMinutes(20),
我猜错了。只有在后续请求中,用户才能通过身份验证
这是我的密码
var fat = new FormsAuthenticationTicket(
1,
username,
DateTime.Now,
DateTime.Now.AddMinutes(20),
rememberMe,
contact.Id + "," + contact.Role.Id,
FormsAuthentication.FormsCookiePath);
HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)));
在这一点上,如果我检查HttpContext.Current.Request.IsAuthenticated,我会得到false,我认为在这一点上用户是经过身份验证的
这是我的配置
<authentication mode="Forms">
<forms loginUrl="/Admin/Login.aspx" name="FormAuthentication" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
谢谢 因为它就是这样工作的。此属性尝试从请求中读取Cookie,但没有任何Cookie,因为当发送请求时,客户端WAN尚未经过身份验证。设置cookie,并在连续的客户端请求中发送到服务器
成功验证用户后,您可以使用Response.redirect
重定向到站点的已验证部分。另一种可能是直接使用该方法,它执行两件事:发出cookie并重定向到
标记中指定的页面。五个问题,不接受。不好!!