Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 218

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report