2

I'm creating a website in ASP.NET (Framework 4.0). I have maintained session in this website. I have written code for logout where FormsAuthentication , session value is Abandon . My Code as follow for logout button click .

 protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["ASP.NET_SessionId"] != null)
        {
            Response.Cookies["ASP.NET_SessionId"].Value = string.Empty;
            Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-20);
        }
        FormsAuthentication.SignOut();
        Session.Abandon();
        Response.Redirect(FormsAuthentication.DefaultUrl);


    }

How to disable / block /prevent to previous page when logged out & without javascript. Because when user gets logout ,he redirect to default page, but users click browser back button he redirects to previous page (i.e users home page ) instead of login page.

Ronp
  • 199
  • 3
  • 15

2 Answers2

4

I think you have to use javascript . If you are using master page , then write this code in head section.

<script type="text/javascript">
        window.history.forward(-1);
    </script>

And in Master page (Page_Load) mode write this code.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
  • 1
    Yes your code is useful . But is their any other way to write code instead of javascript ? Because javascript can be disabled by user. – Ronp Feb 02 '16 at 18:05
1

You can use this , but i think it will work on some browser. Use on this Master (page_load).

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(360));
Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetSlidingExpiration(true);

Follow this Link for more details.

Community
  • 1
  • 1
  • 1
    Your 1st code works ,but this code doesn't work when user clicks browser back button. – Ronp Feb 02 '16 at 18:35