How to clear Session or Cookie when exiting safely in Asp.net
Editor to share with you how to clear Session or Cookie when you exit safely in Asp.net. I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.
Overview:
Click exit in the website, if you just redirect to the login / exit page, enter the address of a page after login in the browser address bar, such as the home page, and you will find that you can access it without logging in. This so-called exit is not safe.
So how to exit safely?
That is to click exit and clear the corresponding Session or Cookie.
Clear the code for Session:
Session.Clear (); Session.Abandon ()
Clear the correct code for Cookie (assuming the Cookie name is UserInfo):
If (Request.Cookies ["UserInfo"]! = null) {Response.Cookies ["UserInfo"] .Expires = DateTime.Now.AddDays (- 1);}
If you need to clear all Cookie, traverse:
For (int I = 0; I