栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何强制退出网站的所有用户?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何强制退出网站的所有用户?

正如乔建议的那样,您可以编写一个HttpModule来使给定DateTime之前存在的任何cookie无效。如果将其放在配置文件中,则可以在必要时添加/删除它。例如,

Web.config:

<appSettings>  <add key="forcedLogout" value="30-Mar-2011 5:00 pm" /></appSettings><httpModules>  <add name="LogoutModule" type="MyAssembly.Security.LogoutModule, MyAssembly"/></httpModules>

MyAssembly.dll中的HttpModule:

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();        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/421207.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号