ASP.NET MVC 3 FormsAuthentication ReturnURL
I am using Forms Authentication in my MVC 3 app and having a problem with my return URL.
开发者_运维知识库When I mark an action <Authorize>
on the Home controller, it redirects to the login page and works, but the return URL is then /
, so when it redirects, it is redirecting to the root of the the current URL Authorize
.
So the URL's are like this:
http://localhost/ - Controller = Home - Action = Index
http://localhost/Authentication/LogOn
I end up with this: http://localhost/Authentication/LogOn?ReturnURL=~%2F, I need to get back to http://localhost/
Help!! :)
Try changing your Account controllers LogOn action to something like this:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
http://localhost/Authentication/LogOn?ReturnURL=~%2F, it means home url is duplicated
精彩评论