![](/img/trans.png)
[英]HttpContext.SignInAsync() fails to set cookie and return User.Identity.IsAuthenticated as true
[英]At what time User.Identity.IsAuthenticated set to true
在我的login.aspx页面中,我使用<asp:Login>
控件,如果User.Identity.IsAuthenticated = true,我需要指定一些值。
正如提到这里当用户提交他或她的登录信息,登录控制第一引发LoggingIn事件,然后Authenticate事件,最后的loggedIn事件。
所以我检查了这个值如下:
protected void Login_LoggedIn(object sender, EventArgs e)
{
int x = 0;
if (User.Identity.IsAuthenticated)
x = 5;
}
但是这个值总是假的 。 我的问题如下:
用户输入其凭据并单击“登录”按钮。 发生回发。
1.传入请求进入ASP.NET管道。
2. Application_Authenticate事件触发。 此时,ASP.NET运行时不知道用户是谁,因此User.Identity.IsAuthenticated = false
3.登录页面的生命周期,
4.由于您将e.Authenticated设置为true,因此将触发Login控件的Authenticate事件并创建表单身份验证票证。
5.登录控件的LoggedIn事件触发。 此时,我们仍然在同一个请求,所以User.Identity.IsAuthenticated仍然是假的!
更多信息,请阅读此链接: http : //forums.asp.net/t/1177741.aspx?User + Identity + IsAuthenticated+remains+false+why+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.