0

I m facing the problem of Access to my pages even after Logout.. I have visited many forms but majority saying Disable back button.. I want to achieve this through code rather than disabling back button.

My problem :

I m able to access previous page through back button after logout and I m able to access by typing the URL like "localhost/admin.aspx" after logging off...

Please help me in avoiding above two problems?? I m using C#..! Many thanks in advance..

rtvalluri
  • 557
  • 2
  • 6
  • 22

6 Answers6

0

Try this

protected void LoginStatus1_LoggedOut(object sender, EventArgs e)
{
    FormsAuthentication.SignOut();
    Roles.DeleteCookie();
    Session.Clear();
}
0

Your pages are cached by browser which helps to improve performance of page loading. It is possible to disable output caching. You can find some considerations how to do that here http://forums.asp.net/t/1268449.aspx.

Egor4eg
  • 2,678
  • 1
  • 22
  • 41
0
  1. To disable the back button using javascript code.
  2. In case of manual session management, Check for session on the pages meant to use only after login. On its PageLoad event use something like this

    if(Session["SomeVar"]==null) {

           // redirect to login page or somewhere else
    }
    

    If you are using Membership Provider then I think it will do automatically for you.

Also you can set Cache Expiration Policy to avoid back buttons.Below is the code for the same

private void DisableClientCaching()
    {
        // Do any of these result in META tags e.g. <META HTTP-EQUIV="Expire" CONTENT="-1">
        // HTTP Headers or both?

        // Does this only work for IE?
        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        // Is this required for FireFox? Would be good to do this without magic strings.
        // Won't it overwrite the previous setting
        Response.Headers.Add("Cache-Control", "no-cache, no-store");

        // Why is it necessary to explicitly call SetExpires. Presume it is still better than calling
        // Response.Headers.Add( directly
        Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
    }
0

Try to use the above

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
        Response.Cache.SetNoStore();
        Response.AddHeader("Pragma", "no-cache");
        Response.Expires = 0;
kostas ch.
  • 1,960
  • 1
  • 17
  • 30
0
  1. In login form on login button click

    Session["ABC"] = UserNameTextBox.Text;
    Session["Username"] = UserNameTextBox.Text;
    
  2. On each page load event other than login.aspx

    string a = Convert.ToString(Session["ABC"]);
    if (a == "")
    {
        Response.Redirect("Login.aspx");
    }
    
Hitesh
  • 3,449
  • 8
  • 39
  • 57
SumitG
  • 41
  • 2
  • 8
-1

Clear the session while logging out. Session.Abandon()

Saritha.S.R
  • 800
  • 1
  • 6
  • 19