In my application after login I am going into home page. But from home page if I press browser's back button again the system sending me to the login page.
How can I resist my user doing so. If they do press the back button while he/she is logged in, the system will resend him/her to that same page, not in login.
At the top of your Login.aspx page, add the following line to prevent browsers from caching the login page:
<%@ OutputCache Location="None" NoStore="True" %>
Then, in Login.aspx.cs, redirect to your home page if the user is already logged in:
protected override void OnPreInit(EventArgs e)
{
if (this.Request.IsAuthenticated)
this.Response.Redirect("~/Home.aspx");
base.OnPreInit(e);
}
In the login page add a snippet that checks whether the user is already logged in. If he/she is; then redirect the user to login page.
// In the login page
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
Response.Redirect("~/Default.aspx");
}
Don't do that; the only thing you will accomplish is being annoying.
The back button is supposed to go back.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.