ASP.NET Simple Logoff Function

  • 2021-06-29 10:46:40
  • OfStack

Principle: Empty Session

1.Web Form: index.aspx

* < a href="logoutHandler.ashx" > Cancellation < /a >

2.1 General Processor: LogoutHandler.ashx


/// <summary>
/// LogoutHandler  Summary description of 
/// </summary>
public class LogoutHandler : IHttpHandler,IRequiresSessionState
{
  public void ProcessRequest(HttpContext context)
  {
    context.Session.Clear();  // Remove all keys and values from the session state collection 
    context.Session.Abandon(); // Cancel the current session 

    context.Response.Redirect("/account/login.aspx");  // Jump to Login Page 
  }

  public bool IsReusable
  {
    get
    {
      return false;
    }
  }
}

3.Complete.

The above is the whole content of this article, I hope you like it.


Related articles: