可能重复:
http.context.user和thread.currentprincipal之间的区别以及何时使用它们?
这两个在ASP.NET应用程序中有什么区别?
我知道在HttpContext.User.Identity
用户通过身份验证时设置了FormsAuthentication
.但什么时候Thread.CurrentPrincipal.Identity
设置?
他们总是保持相同的价值吗?
对于无法访问的应用程序的其他层,这仍然适用HttpContext
吗?
我正在使用ASP.Net Identity来管理我的用户.
在调用以下内容后我发现:
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, identity);
Run Code Online (Sandbox Code Playgroud)
当我检查用户当前是否通过HttpContext.Current.User.Identity.IsAuthenticated
它进行身份验证返回false
.
我设法true
通过执行以下操作来获取此信息:
FormsAuthentication.SetAuthCookie(model.UserName, false);
Run Code Online (Sandbox Code Playgroud)
是否可以设置HttpContext.Current.User.Identity.IsAuthenticated
为true
?