asp.net exit login (after the exit Click Browser back problem can still return to the page problem) _ Practical Tips

Source: Internet
Author: User
Tags httpcontext
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");
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.