【发布时间】:2011-04-29 13:23:00
【问题描述】:
我已经使用表单身份验证在我的网站上创建了一个登录名, 我不明白为什么在创建票证并将其添加到 cookie 之后
如果我检查HttpContext.Current.Request.IsAuthenticated
我弄错了。只有在连续请求时,用户才会通过身份验证
这是我的代码
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 我得到错误,我认为此时用户已通过身份验证...
这是我的配置
<authentication mode="Forms">
<forms loginUrl="/Admin/Login.aspx" name="FormAuthentication" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
谢谢。
【问题讨论】:
-
五个问题,不接受。不好!!
标签: c# asp.net cookies forms-authentication