I found a work around.
I'm working in ASP.NET
C#
. I have a Master Page
for all the pages of the site except for the Login
page. In the Master Page
Sever Page Load event
I get the Url
of the referring page and check if it contains the root of the the site, if not I redirect to the Login
page and since it doesn't have that Master Page
it displays.
This works if I try to get to a page from another site or if I enter the Url
to the address box of the browser. So if you close the tab and you try to reenter from another tab or reopen the tab, even tho the cookie hasn't been killed you can't reenter the site without going thru Login
. This works also even if you haven't closed the tab and your navigating between different sites in the same tab.
This is the code
if (Request.UrlReferrer == null || !Request.UrlReferrer.AbsoluteUri.ToString().Contains("root"))
{
Response.Redirect("~/Account/Login.aspx");
}
When navigating from within the site there's no problem even if you open a link to another page in the site to another tab it opens.
If you want to be additionally sure you can kill the session and authentication cookie in that if
clause before redircting to the Login
page.
This won't work when a user navigated to another site in the same tab and presses the browsers back to
button because that works on cache and doesn't automatically send a request to the server.
So this doesn't kill the session or authentication cookie on closing the tab, but it can help prevent reentering the site without logging in after closing the tab.