Copy codeThe Code is as follows:
Session. Abandon ();
Response. Redirect ("Login. aspx ");
However, after clicking the browser, you can still return to the page just now. This is not acceptable. After searching for it online, many people have encountered such problems and tried some methods, none of them work. But I still find it. Share it.
Http://blog.csdn.net/lhypang2006/archive/2008/03/11/2170751.aspx
Copy codeThe Code is as follows:
Session. Abandon ();
Response. Write ("<script> window. location. href = 'login. aspx '</script> ");
It is easy to change Response. Redirect to Response. Write, and output the script to achieve redirection.
Share another one, which is also about exiting.
Use HttpHandler in Asp. Net
I think the above method is good. Write a class to inherit IHttpHandler.
Copy codeThe Code is as follows:
Public class LogoutHttpHandler: IHttpHandler
{
/// <Summary>
/// Enable HTTP Web request processing by implementing the custom HttpHandler interface of the IHttpHandler interface.
/// </Summary>
/// <Param name = "context"> HttpContext object, which provides reference for internal Server objects (such as Request, Response, Session, and Server) used to provide services for HTTP requests. </Param>
Public void ProcessRequest (HttpContext context)
{
FormsAuthentication. SignOut ();
Context. Response. Redirect ("Login. aspx", true );
}
Modify web. config and add the following script to <system. web> </system. web>:
Copy codeThe Code is as follows:
<HttpHandlers>
<Add verb = "GET" path = "Logout. aspx" type = "LogoutHttpHandler"/>
</HttpHandlers>
Compile the class into a dll in the article, or you can just add this class in App_Code.
The previous ProcessRequest does not clear the Session. Response. Redirect is also used. You can also click back to return to the original page. I changed it.
Copy codeThe Code is as follows:
Public class LogoutHttpHandler: IHttpHandler, IRequiresSessionState
{
Public void ProcessRequest (HttpContext context)
{
// FormsAuthentication. SignOut (); // you can skip this step.
Context. Session. Abandon ();
Context. Response. Write ("<script> window. location. href = 'login. aspx '</script> ");
}
}
In this way, you do not need to add a page Logout. aspx, And the exit code is also simple.
Copy codeThe Code is as follows:
Protected void Exit_Click (object sender, EventArgs e)
{
Response. Redirect ("Logout. aspx ");
}