Well, as I do sometimes, I answer my own question to add more information on how I resolved a problem after getting other people answer (In this case, Darin Dimitrov).
Briefly, @Darin Dimitrov explained to me that I need to supply the returnUrl
if the redirection to LogOn
action method is not the result of forcing a user to supply credentials (when the method is trying to access is decorated with a [Authorize]
attribute). I need to use new { returnUrl = RouteData.Values["action"] }
to supply that value.
Here are some problems:
Intellisense did not recognize `RouteData.Values["action"], I needed to use
Page.RouteData.Values["action"]`
I kept getting the following error: "the resource cannot be found", url showing http://example.com/Account/Whatever_action_is_in_the_returnUrl
. That make sense because I did only supply the action string.
I did this
new
{
returnUrl = Page.RouteData.Values["controller"] + "/" + Page.RouteData.Values["action"]
}
But I got the some error:"the resource cannot be found", url showing http://example.com/Account/myController/myAction
. The account was still in the Url, causing the same error.
Finally, I added an other slash in the beginning then it worked.
new
{
returnUrl = "/" + Page.RouteData.Values["controller"] + "/" + Page.RouteData.Values["action"]
}
It looks like it's important to know many faces of the the redirections business. So far, I've mostly used RedirectToAction()
.
Thanks @Darin Dimitrov.