0

I have 2 pages home.aspx and admin.aspx

After successfully logging into admin.aspx when i click back button of browser, it does redirect to home.aspx but that i don't want.

I am checking session variable persistence on home.aspx but for some reason its not working!!

Here's the code

home.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["aname"] != null)//should work as session will not be null!
    {
        Response.Redirect("admin.aspx");
    }
    } //.....some code..after this 


        if (dt.Rows.Count != 0)
        {

            Session["aname"] = TextBox11.Text;
            Response.Redirect("admin.aspx");
        }

admin.aspx.cs code

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["aname"] == null)
    {
        Response.Redirect("home.aspx"); 
    }

} //some code after this..

protected void logoutbutton_Click(object sender, EventArgs e)
{
    Session["aname"] = null;
    Session.Abandon();
    Session.Clear();
    Response.Redirect("home.aspx");
}

NOTE:(things working fine)

1.login working sucessfully

2.logout working sucessfully

3.back button is disabled once loggedout(not going on admin.aspx)

Issue:

When logged in i.e. on admin.aspx ,on clicking back button it redirects to home.aspx which i don't want. i expect it to remain on same admin.aspx

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
Jai hind
  • 85
  • 1
  • 11

2 Answers2

1

ok.. finally trying all your solutions..this code worked on adding in my masterpage (in head tags)

<script type = "text/javascript" >

function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);
window.onunload=function(){null};

</script>

full details on this page

Jai hind
  • 85
  • 1
  • 11
0

You can push the Window History forward to prevent the back button. This has work for me in most cases. Include this JavaScript on your Admin.aspx page.

$(function() {
    window.history.forward();
});
Elim Garak
  • 1,728
  • 1
  • 16
  • 21