问题描述
的首先要注意的是在我的应用程序,如果你退出你的会话仍然有效,你不只是被重定向回到登录页面,但留在同一页上是很重要的。
随着中说 - 无论这两种方式我用在MVC应用程序退出
With that said - whichever of these two ways I use to sign out in an MVC application
FormsAuthentication.SignOut()
WebSecurity.Logout()
的效果是相同的,既没有的下列属性的变化,以反映注销如果我立即访问他们
the effect is the same and neither of the following properties changes to reflect the logout if I immediately access them :
User.Identity.Name
Thread.CurrentPrincipal.Identity
现在 - 如果我做一个重定向,或者只是重新加载页面话,显然这些属性被更新为空的用户。他们只是不立即也就是说 User.Identity.Name
重新presents,只是注销用户。
Now - If I do a Redirect, or just reload the page then obviously these properties are updated to a null user. They just don't immediately meaning that User.Identity.Name
represents a user that just logged out.
这是一个问题,因为我要生成表单文本您登录为XXX
登录/注销后 - 这可能是一个AJAX的情况是:重定向是不可能的。
This is a problem because I want to generate text of the form You are logged in as XXX
after login/logout - and this may be in an AJAX situation where a redirect isn't possible.
我很好奇,如果有任何的方式来触发的IPrincipal
注销(或登录)后自行复位。
I'm curious if there's any way to trigger the IPrincipal
to reset itself after a logout (or login).
我认为人们通常只是重定向()
后退出()
调用,所以这是从来没有一个问题,但在AJAX情况这并不总是实际的。
I assume people normally just Redirect()
after a Logout()
call so this is never an issue, but in an AJAX situation this is not always practical.
我目前的解决办法是抽象的身份在自己的包装,所以一旦我登出我就可以更新。我只是有点担心,这可能有一些模糊的副作用,特别是如果有人访问的IPrincipal
直接ADN不是通过包装。
My current solution is to abstract the Identity in my own wrapper, and so once I'm logged out I can just update that. I'm just a little concerned that this could have some obscure side effects especially if somebody accesses IPrincipal
directly adn not through the wrapper.
推荐答案
这是ASP.NET管道事件的核心限制,因为它涉及到窗体身份验证。这也使得它容易受到重放攻击,rel=\"nofollow\">知识库文章900111 在可能会有所帮助。
这篇关于为什么不WebSecurity.Logout * *立即更新IPrincipal.User为空的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!