0
votes

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!! :)

2
what is your localhost default route ? - Naz
@Nazar - routes.MapRoute( _ "Default", _ "{controller}/{action}/{id}", _ New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _ ) - Sam

2 Answers

2
votes

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);