Nigar
Nigar

Reputation: 59

Clear Session in ASP .NET MVC 5?

I have a question. I work in ASP .NET MVC 5 . I want to prevent is that , after logging out , then I click the back navigation button , I don't want to go back to the previous page . Is there anyone who can help me? I use Session Clear and Abandon methods and FormsAuthentication's SignOut method.But this not sole my problem.

Upvotes: 1

Views: 5039

Answers (3)

Sercan Elvanağacı
Sercan Elvanağacı

Reputation: 98

Should use your OutputCache action method

[OutputCache(NoStore = true, Duration = 1)]

or

Global.asax.cs you add

protected void Application_BeginRequest()
{                
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
    Response.Cache.SetNoStore();                                 
}

Do session check in action method

if (Session["xxx"] == null)
{
     return View("aaaa");
}

Upvotes: 2

Mahesh Odedra
Mahesh Odedra

Reputation: 59

[See the Image]
1)sign out the user
2)put [Authorize] attribute before Controller

This will redirect the user to login page

Upvotes: 1

Haitham Shaddad
Haitham Shaddad

Reputation: 4456

This happens because the browser caches the data, you have to clear the browser cache by setting some headers in the page response.

You can do that using the answer of this question How to refresh page on back button click?

Upvotes: 1

Related Questions