Get the App
SLTechnology News&Howtos  ›  Development  › 

How to log out of the system and clear Cookie by ASP.NET

Shulou Source: shulou.com Published: 2022-06-01 00:05:11 10月04日 Update

This article mainly introduces the relevant knowledge of "how to log out of the system and clear Cookie by ASP.NET". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope that this article "how to log out of the system and clear Cookie in ASP.NET" can help you solve the problem.

1. Front-end page code:

The front-end page code mainly displays the visual button code for exiting the system or website. The code is as follows: (please ignore the project keyword: CPU)

@ CPU.UserProfile.User.UserID @ using (Html.BeginForm ("LogOff", "Account", FormMethod.Post, new {id = "logoutForm", style = "padding: 12px 0px" "}) {@ Html.AntiForgeryToken () Log Out} Number of people online: @ System.Web.HttpContext.Current.Application ["OnLineUserCount"] 2. Background logic processing code:

The background code is mainly used to deal with the events when the foreground clicks the button: exit the system and clear the system Cookie

[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult LogOff () {FormsAuthentication.SignOut (); / exit login System.Web.HttpContext.Current.Session.Abandon (); / / clear cache return RedirectToAction ("Login", "Account");} 3. Interface effect:

This is the end of the introduction on "how ASP.NET logs out of the system and clears Cookie". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: System code knowledge front end background button industry page processing different practical event number of people keywords content foreground practicality actual effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Docker vpn NVidia