Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session variable clearing methods will clear current browser sessions only?

Following session variables clearing methods are used in log out click

Session.Clear(); 
Session.RemoveAll();
Session.Abandon();

If i open my website in two browsers and log out from one browser.The session variables are not clearing in the second browser.So it is not redirecting to log out.

The above mentioned methods will clear only the current browser session variables only? what is the efficient way to remove all the browser sessions??


1 Answers

In general, when two browsers connect to your website, there are two different sessions will be instantiated. The information in each session is independent from all other ones. So when you remove/clear the session, only the current session will be affected.

To destroy all sessions, suppose that you are using InProc mode for session state (there are other modes => https://msdn.microsoft.com/en-us/library/ms178586(v=vs.140).aspx), you can destroy all sessions by restarting the Application Pool. There are some examples on MSDN site.

        ServerManager serverManager = new ServerManager();
        ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
        foreach (ApplicationPool applicationPool in applicationPoolCollection)
        {
            //...
            applicationPool.Recycle();
            //...
        }
        // CommitChanges to persist the changes to the ApplicationHost.config.
        serverManager.CommitChanges();

P/s: The ServerManager class resides in Microsoft.Web.Administration package. This behavior shouldn't be implemented in log out event.

There are options to restart the app pools also

  • Modify web.config file
  • Upgrade a new .dll file
  • Use IIS manager
like image 153
hazjack Avatar answered Mar 04 '26 00:03

hazjack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!