Copy Code code as follows:
Session.Abandon ();
Response.Redirect ("Login.aspx");
But this point Click Browser back can still go back to the page just now, this can not be, on the internet for a while, there are many people encounter such problems, tried some methods, are not useful. But finally find, share.
Http://blog.csdn.net/lhypang2006/archive/2008/03/11/2170751.aspx
Copy Code code as follows:
Session.Abandon ();
Response.Write ("<script>window.location.href= ' Login.aspx ' </script>");
Very simple, is to change Response.Redirect to Response.Write, output script, realize jump.
Share one more, also about exit.
HttpHandler in the magical asp.net
The above method I feel very well, write a class to inherit IHttpHandler
Copy Code code as follows:
public class Logouthttphandler:ihttphandler
{
<summary>
Enable processing of HTTP WEB requests by implementing a custom HttpHandler of the IHttpHandler interface.
</summary>
<param name= The "context" >httpcontext object, which provides references to internal server objects (such as requests, Response, sessions, and servers) that are used to provide services for the HTTP request. </param>
public void ProcessRequest (HttpContext context)
{
FormsAuthentication.SignOut ();
Context. Response.Redirect ("Login.aspx", true);
}
To modify the web.config, add the following script in <system.web></system.web>:
Copy Code code as follows:
<add verb= "Get" path= "logout.aspx" type= "Logouthttphandler"/>
It would be nice to compile the class into a DLL in the article, or just add such a class to the App_Code.
And the above ProcessRequest did not clear the session. And also with Response.Redirect, click Back can also return to the original page. I changed it.
Copy Code code as follows:
public class Logouthttphandler:ihttphandler, IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
FormsAuthentication.SignOut ()//This may not be necessary.
Context. Session.Abandon ();
Context. Response.Write ("<script>window.location.href= ' Login.aspx ' </script>");
}
}
This does not add a page logout.aspx, the exit code is also simple.
Copy Code code as follows:
protected void Exit_click (object sender, EventArgs e)
{
Response.Redirect ("logout.aspx");
}