Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created a session on log-in into a particular admin page in my asp.net mvc application. when i click logout it redirected me to the logout page as instructed but when i click the back navigation button, it sends me back to the page i logged out from.
what 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. it should tell me session expired or redirect me to login page.

this is the logout button located in my layout page

HTML
<ul class="right chevron">
       <li>@Html.ActionLink("Log Out", "logout", "Home")</li>
</ul>


this is my controller code

C#
public ActionResult logout()
        {
            Session.Abandon();
            @tempData["sess"] = Session.Mode;
            return View();
        }

when i check the session mode on the logout page, it shows me InProc
Posted
Updated 10-Jun-16 13:02pm
v3

1 solution

When you click on browser back button, it brings a page from cache. To prevent this you could remove the cache like the following:

C#
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();


You can also add a meta to your view that clears the cache.

Check this discussion for details of the workaround: asp.net mvc - After logout if browser back button press then it go back last screen - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900