This article mainly introduces how to close the ie window to clear the Session. If you need a friend, please refer to it and hope to help you.
The Code is as follows:
// Function window. onunload () {alert ('This is what you want to do. It is done after you close the webpage! '); Location = 'sessionclear. aspx ';}
// Function window. onbeforeunload () {alert ('This is what you have to do. It was done before closing the webpage! ')}
Function window. onunload (){
If (window. screenLeft> = 10000 & window. screenTop> = 10000) | event. altKey ){
Alert (window. screenLeft + "," + window. screenTop );
// The Action to be triggered when the user shuts down abnormally
Location = 'handler1. ashx ';
}
}
Script
Handler1.ashx:
The Code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. Services;
Using System. Web. SessionState;
Namespace WebApplication1
{
///
/// $ Codebehindclassname $ abstract description
///
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
Public class Handler1: IHttpHandler, IRequiresSessionState
{
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
Context. Session. Abandon ();
Context. Session. Clear ();
}
Public bool IsReusable
{
Get
{
Return false;
}
}
}
}
Explanation:
Generally, a website in the form of a member creates a session or Cookie after the member logs in. Then, the member needs to exit the connection or click the button to exit when the member exits. When a member closes the form directly, a series of exits related to exit are not triggered. These will not be cleared until the server session expires.
Fortunately, on the network, we finally found a way to capture events that users can use Alt + F4, right-click the title bar, double-click the title bar, and directly press the close button. Of course, it cannot be captured to minimize to the taskbar and then close it.
The Code is as follows: