0

User first go through registration and then after successful registration, user redirects to welcome page. At welcome page user successfully logged-in the website. But if someone click the back browser button then the previous registration page doesn't show any log-in user. And when we refresh that page then it shows user login. May be the reason that without refreshing the page it doesn't reload itself with cookies(login session). We want that either user can't go backward or if it go backward to registration page then the webpage already has details of login session. We are developing in MVC-Asp.NET

Please guide. Thanks in advance.

  • that's how browsers behave by design when you press the back button. You could however have a timed JS call to the server always running on the 1st page (even when the user is logged out) that returns a simple result signifying if the user is logged in and to alter what you see on the page appropriately/redirect/do whatever....or set a cookie and have the 1st page look for it....there are a few options – scgough Nov 22 '17 at 11:40
  • 2
    Possible duplicate of [ASP.NET MVC how to disable automatic caching option?](https://stackoverflow.com/questions/12948156/asp-net-mvc-how-to-disable-automatic-caching-option) – mjwills Nov 22 '17 at 11:47
  • https://stackoverflow.com/questions/20895489/outputcache-setting-inside-my-asp-net-mvc-web-application-multiple-syntax-to-pr is also a good read on the issue. – mjwills Nov 22 '17 at 11:49
  • @mjwills fair point - I jumped the gun there a little! – scgough Nov 22 '17 at 11:58

1 Answers1

0

Add these attributes on your registration action method like.

[HttpGet]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] 
public ActionResult registration()
{
  //your code here
}

SOURCE:Handling browser back button

Hasan Ali
  • 252
  • 4
  • 13