0

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 ? Commented Mar 29, 2011 at 17:09
  • @Nazar - routes.MapRoute( _ "Default", _ "{controller}/{action}/{id}", _ New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _ ) Commented Mar 29, 2011 at 17:23

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

The FormsAuthentication handles the routing I believe.
I figured it out, I was using RedirectToAction, should have been using just Redirect. Thanks!!
-1

http://localhost/Authentication/LogOn?ReturnURL=~%2F, it means home url is duplicated

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.