简体   繁体   中英

After logout,how to redirect user to login page when he/she will click back button of browser in ASP.NET MVC3

I am working on ASP.NET MVC3 project with C# and SQL SERVER 2008 as a backend.

Mu issue is:

On the Logout Controller am doing

Session.Abandon();

 HttpContext.Response.Cookies.Set(new HttpCookie("Cookie-Name") { Value = string.Empty });

Due to this, session will be cleared and Cookie will also get cleared.

Now I want that if any user will click on Browser's Back button, he/she should be redirected to Login Page.

How can I do this?

Try:

if(!User.Identity.IsAuthenticated)
{
    RedirectToAction("Index", "Home");
}

and use the [Authorize] data annotation on the required actions. You should be doing something like that for all your pages that require a user to be logged in anyway.

Hope it helps.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM