最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to blockprevent user to go back to previous page after logout in ASP.NET - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Feb 2, 2016 at 17:56 RonpRonp 1993 silver badges15 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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();

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.

发布评论

评论列表(0)

  1. 暂无评论