Here’s the definition of the LogOn post action method
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
// more inside
}
I’ve a basic question. Does the framework supplies the string returnUrl? or I do have that responsibility?
Thanks for helping.
It depends on who is calling this method and whether this parameter is supplied in the POST request. For example if the user tries to access a controller action decorated with the
[Autorize]attribute and he is not authenticated the framework will automatically redirect to theLogOnaction (the one that renders the form, not the one with[HttpPost]) and supply thereturnUrlparameter. Then you could have a hidden field in the logon form to persist its value so that when the user enters his credentials and submits the form to theLogOnaction, in case of successful login, he is redirected to the initially requested page.