1

I have the following:

    [Route("login")]
    [AllowAnonymous]
    public ActionResult Login(string returnUrl) {
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

However, when I navigate to any [Authorized] route as an unauthenticated user, I get navigated to /Account/Login, which is an invalid route thanks to me overriding it to login. How do I tell MVC5 to use the attribute routes when redirecting in this case?

SB2055
  • 12,272
  • 32
  • 97
  • 202
  • In your web.config under `system.web->authentication->forms` there is an attribute `loginUrl` - what is that equal to on yours? – wal Dec 12 '14 at 03:01
  • @wal - even if I change that from the default `Account/Login` to `login`, I get redirected to `Account/Login` – SB2055 Dec 12 '14 at 03:02
  • and when you navigate directly to `your-domain.com/login`? could you have left an `[Authorized]` attr on the controller or base controller? – wal Dec 12 '14 at 03:04
  • /login works, I want it to redirect, just to /login, not the default Account/Login, because Account/Login does not work. – SB2055 Dec 12 '14 at 03:05
  • And even if I had, `[AllowAnonymous]` should negate that, no? – SB2055 Dec 12 '14 at 03:06
  • yes probably would negate it actually (have not checked) - – wal Dec 12 '14 at 03:09
  • i am surprised you are redirected even tho you have changed `loginUrl` - what happens if you change loginUrl to something else, say something invalid like `~/doesnotexist` ? – wal Dec 12 '14 at 03:11
  • @StephenMuecke - try overriding an MVC controller action with attribute routing, and then navigate to the default action's route, and you'll understand. – SB2055 Dec 12 '14 at 03:19
  • @wal - I still get /Account/Login :/ – SB2055 Dec 12 '14 at 03:22
  • see http://stackoverflow.com/questions/6447728/formsauthentication-loginurl – wal Dec 12 '14 at 03:31

1 Answers1

2

In Startup.Auth there is a setting I had to change:

            LoginPath = new PathString("/login"),
SB2055
  • 12,272
  • 32
  • 97
  • 202