Moji
Moji

Reputation: 1830

back button of browser does not return the desired view and returns a view in cache instead

I have a register page where the user can register and after registration, his token will be stored. then after registration I will redirect him to the shop page. if he is registered and he clicks the back button of the browser, he should be redirected to home page(and not see the registration page again). but now with my current code when the user presses back button after registration, he moves back to the registration page!. any ideas? here is my controller that returns the homepage view if he is logged in and registered:

public virtual ActionResult Register(string returnUrl, string invitationCode = null,
            string emailAddressOrMobileNumber = null)
        {
            if (Request.IsAuthenticated) return RedirectToAction(MVC.Home.Index());}

Upvotes: 0

Views: 231

Answers (2)

Hien Nguyen
Hien Nguyen

Reputation: 18975

You can set these code in Home:Index action to clear cache control. You also need check UrlReferrer to confirm go Home by Register page.

if (Request.UrlReferrer.PathAndQuery == "/register")
{
    HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
    HttpContext.Current.Response.AddHeader("Expires", "0");
}

Upvotes: 0

Alaaeddine HFIDHI
Alaaeddine HFIDHI

Reputation: 886

If you will return just a view you should :
1) Add an html section or DIV into your view or intro your layout and set the css properties to put this DIV on the bottom of your page like:

HTML :

<div id="bottom" > </div>

CSS :

 #bottom { 
        height: 40px; 
        position: fixed; 
        bottom:0%;
        width:100%; 
        background-color: #393838; 
        opacity: 1;
    }

2) In the return action you should return your route url + the id of your DIV to scroll to this div
Controller :

public virtual ActionResult Register(string returnUrl, string invitationCode = null,
            string emailAddressOrMobileNumber = null)
        {
            if (Request.IsAuthenticated) return RedirectToAction(MVC.Home.Index());

}
return Redirect(Url.RouteUrl(new { controller = "Controller", action = "Action" }) + "#bottom");
}

Upvotes: 0

Related Questions