hello sally,
For preventing multiple logins you need to expire session
when user is closing the browser.
To detect the closing event in asp.net
you need to write javascript and call asp.net page methods to
abandon (expire) session.
There are two ways to do so.
1. Either you can directly call .aspx page from unload method of body.
Let's say you wrote in testa.aspx
<body onunload="window.location.href='TestB.aspx';">
Then on testB.aspx you wrote something like following
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Call MyBase.OnLoad(e)
' End The Session
Session.Abandon()
' Build A JavaScript String That Will Close This Web Browser Window
Dim s As String = ""
s &= "<script language=""javascript"">"
s &= "window.close();"
s &= "</script>"
' Add The JavaScript To The HTML Stream
Page.RegisterClientScriptBlock("close", s)
End Sub
2. Second method is use javascript function to call .aspx page methods as follows
<body onunload="HandleClose()">
<script language="javascript" type="text/javascript"> //<![CDATA[ function HandleClose() { alert("Killing the session on the server!!"); PageMethods.AbandonSession(); } //]]> </script>
//In code behind You wrote as follows
[WebMethod]
public static void AbandonSession()
{
HttpContext.Current.Session.Abandon();
}
Hope this will help!