Hi Asif Hameed,
*Please refer to my next reply. Sorry for inconvenience*
------------------------------------------------------------------------------------------------
The problem may be casued by session. When the page is closed, the Session hasn't been disposed and when the user opens the page again, the code for detecting Session["loginStatus"] considers that the user has been logged in.
To deal with this issue, I suggest you using JavaScript function, which is fired when page unloads, to call behind code to dispose the session.
Have a try on the test demo below. I have written some comments to it:
<%@ Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
//when page is unloading, we find the unload button and click it.
window.onbeforeunload = function() {
if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altKey) {
document.getElementById("unload").click();
}
}
</script>
<script runat="server">
protected void DoUnLoad(object sender, EventArgs e)
{
//write some texts to do the test.
System.IO.File.AppendAllText(Server.MapPath("unLoadTest.txt"), "page has been unload");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--you can set the button's display as none to hide it--%>
<input id="unload" name="unload" runat="server" onserverclick="DoUnLoad" type="button" value="button" />
</div>
</form>
</body>
</html>
In your case, you can replace the code of writing texts with some other code clearing the session, like this:
Session["loginStatus"] = null;
Best Regards
Shengqing Yang
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )