在应用程序启动清除所有会话 [英] Clear all sessions on application start

查看:105
本文介绍了在应用程序启动清除所有会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我重新启动我的ASP.Net应用程序,登录用户的凭据被记住,他们可能会发现themserves自动登录。结果
只要用户的会话变量,设置在登录时,不进行沿此行为是不必要的。
所以,我怎么能忘记在应用程序的所有会话的开始?

I noticed that when I restart my ASP.Net application, logged users' credentials are remembered and they may find themserves automatically logged in.
This behaviour is unwanted as long as the users' session variables, set at login time, are not carried along. So, how can I "forget" all sessions on the application start?

我知道我不能使用 Session.Abandon()的Application_Start 事件。

I see that I can't use Session.Abandon() in the Application_Start event.

推荐答案

使用此code,当一个新的会话启动时即添加在Global.asax中

Use this code when a new session is started i.e. add it in Global.asax

    #region remove all cookies

    string[] myCookies = Request.Cookies.AllKeys;
    foreach (string cookie in myCookies)
    {
        Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
    }

    #endregion

这篇关于在应用程序启动清除所有会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆