Reputation: 35
I have two API's:
Functionality:
Initially, I am on login screen and on pressing the login button, I go to home screen.
When I'm on home page screen and I logout using the log out button, I am redirected to login screen.
In /home API, following is the condition:
if (userLoggedIn()) {
return new ModelAndView("/homePage");
} else {
return new ModelAndView("/loginPage");
}
Issue:
When I logout and move to login page, I click on back button of the browser. I am redirected to home page. (incorrect)
However, if I open the home page directly using url, I am redirected to login page (correct)
I debugged the application and I found that on pressing the back button, the control does not even go in the /home API.
How can I ensure that on pressing back button, my screen is redirected to login page?
Upvotes: 0
Views: 45
Reputation: 35
Found a solution. My issue is fixed with this.
In the servlet, add the following lines for no caching.
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
Upvotes: 1
Reputation: 29
Set the [OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] to the action. This way the request will be made also on back button and your functionality will make the rest of redirects.
Upvotes: 0