本文介绍了我如何强制注销的所有用户对网站的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的MySQL Connector / NET中,所有的供应商与FormsAuthentication。
I'm using MySQL Connector/.NET, all its providers with FormsAuthentication.
我需要所有的用户在某一时刻注销。该方法 FormsAuthentication.SignOut()
不起作用像我想要的。
I need all users to log out at some moment. The method FormsAuthentication.SignOut()
does not work like I want.
我怎样才能让所有网站用户注销?
How can I make a logout of all site users?
推荐答案
乔建议,你可以写一个HttpModule无效特定日期时间之前的任何cookie present。如果你把这个配置文件,您可以添加/必要时将其删除。例如,
As Joe suggests, you could write an HttpModule to invalidate any cookies present before a given DateTime. If you put this in the config file, you could add / remove it when necessary. For example,
的Web.config:
<appSettings>
<add key="forcedLogout" value="30-Mar-2011 5:00 pm" />
</appSettings>
<httpModules>
<add name="LogoutModule" type="MyAssembly.Security.LogoutModule, MyAssembly"/>
</httpModules>
的HttpModule在MyAssembly.dll程序:
public class LogoutModule: IHttpModule
{
#region IHttpModule Members
void IHttpModule.Dispose() { }
void IHttpModule.Init(HttpApplication context)
{
context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
}
#endregion
/// <summary>
/// Handle the authentication request and force logouts according to web.config
/// </summary>
/// <remarks>See "How To Implement IPrincipal" in MSDN</remarks>
private void context_AuthenticateRequest(object sender, EventArgs e)
{
HttpApplication a = (HttpApplication)sender;
HttpContext context = a.Context;
// Extract the forms authentication cookie
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = context.Request.Cookies[cookieName];
DateTime? logoutTime = ConfigurationManager.AppSettings["forcedLogout"] as DateTime?;
if (authCookie != null && logoutTime != null && authCookie.Expires < logoutTime.Value)
{
// Delete the auth cookie and let them start over.
authCookie.Expires = DateTime.Now.AddDays(-1);
context.Response.Cookies.Add(authCookie);
context.Response.Redirect(FormsAuthentication.LoginUrl);
context.Response.End();
}
}
}
这篇关于我如何强制注销的所有用户对网站的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!