Get the App
SLTechnology News&Howtos  ›  Development  › 

How to clear Session or Cookie when exiting safely in Asp.net

Shulou Source: shulou.com Published: 2022-06-03 19:16:49 11月12日 Update

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

Tags: Services servers events code tags security controls clients methods articles pages processing login usage content name address client that is properties Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux Redmi Docker MariaDB