简体   繁体   English

c#FormsAuthentication注销另一个用户

[英]c# FormsAuthentication signOut another user

I'm using formsAuthentication and as an admin user to the site i would like to be able to sign another user out. 我正在使用FormsAuthentication,并且作为该站点的管理员用户,我希望能够注销另一个用户。 Is this possible ? 这可能吗 ?

Yes it is and you dont even need to write a HttpModule to do it: FormsAuthenticationModule.Authenticate . 是的,您甚至不需要编写HttpModule即可: FormsAuthenticationModule.Authenticate Simply have your event handler take a look at the incoming user and if its in some list of people to be signed out remove them from the list & sign them out. 只需让您的事件处理程序查看传入的用户,如果它在某些要注销的人员列表中,请从列表中将其删除并注销。

No it's not. 不,这不对。 You could probably write something that intercepts authentication, and if it detects a user in the list of users to be logged out does it, but even then what happens if a session times out due to inactivity? 您可能编写了一些东西来拦截身份验证,并且如果它检测到要注销的用户列表中的某个用户,它是否可以进行身份​​验证,但是即使会话由于不活动而超时,会发生什么呢? The user would never have hit that authentication event and would still be queued. 用户将永远不会遇到该身份验证事件,并且仍然会排队。

You could do the following: 您可以执行以下操作:

  1. Write a custom http module and in the AuthenticateRequest event check to see if a user is authenticated and get his username. 编写一个自定义的http模块,然后在AuthenticateRequest事件中检查用户是否已通过身份验证并获取其用户名。
  2. Look up in some common store (probably a database) for a list of users to be signed out. 在某个公用存储区(可能是数据库)中查找要注销的用户列表。
  3. If the user is in this list sign him out . 如果用户在此列表中,请注销他
  4. Remove the user from the list of users to be signed out. 从要注销的用户列表中删除该用户。

And as an administrator you could update the list of users to be signed out. 作为管理员,您可以更新要注销的用户列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM