I have an MVC3 application, in which the user is sent an email, having a link.After clicking on the link in the email, the user is taken to the Login page, then after logging in, to page 2(Second page).
Now, the user can’t go back to the Login page after coming to Second page, and this is the code I’ve written for it(using Sessions)
In the controller of second page:
Session.Add("Login",true);
In the controller of Login page:
if(Session["Login"]==true)
{
//redirect back to Second page
}
else{
//continue
}
Now, the problem is, whenever the user comes to Second page,closes the window, then again clicks on the link(in the email), he is taken to Second page, instead of Login, due to the code above. This should not happen. Any way to avoid this, or find a better way to prevent back button usage??
I thought I could detect Close event of the browser, and clear my Session on that, but it doesn’t seem possible.Please help!
If you want the link in the email to systematically send the user to the LogOn page you could modify it like so:
This way everytime the user clicks on the link in the email no matter if he is already authenticated on your site he will be taken to the LogOn page.