ASP.NET/IIS: Log out all users

醉酒当歌 提交于 2019-12-10 21:04:12

问题


In an ASP.NET 3.5 application running on IIS, how do I force a "deauthentication" of all currently logged-in and authenticated users?

iisreset didn't seem to do the trick!


回答1:


ASP.NET authentication is designed to be resilient to an IISReset due to its use of cookies - performing an IISReset will clear any in-memory information, but the next time a user asks for a page on your site, they will send their authentication token, which (if it hasn't timed out) will still be valid, and the server will re-authenticate them.

You could write something that would effectively log out the user after a restart, by (for example) storing the application start time in a global variable in Application_Start, and then comparing the users LastActivityDate with that value - if it's before the start time, then you can call the appropriate sign-out method during Application_SessionStart or Application_BeginRequest.




回答2:


Changing the authentication form name will then require new authentication from all users.

From:

<authentication mode="Forms">
  <forms name="originalName" loginUrl="~/Account/Login"  />
</authentication>

To:

<authentication mode="Forms">
  <forms name="differentName" loginUrl="~/Account/Login"  />
</authentication>


来源:https://stackoverflow.com/questions/2354989/asp-net-iis-log-out-all-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!