Newbie
Newbie

Reputation: 259

How To Change redirect when using [Authorize]

I understand that to change the url [Authorize] takes you to. You have to edit this line in the web.config

<authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>

What if I have two sign in pages and I want to redirect people from one controller to url /f/signin and people from another controller to /s/signin?

Upvotes: 1

Views: 439

Answers (1)

spender
spender

Reputation: 120548

You could point loginUrl to an action that redirects the user appropriately.

It would look something like this:

public class MySpecialLoginController:Controller
{
    public ActionResult Index(string returnUrl)
    {
        if(returnUrl.EndsWith("/foo")) //dirty. you could do better...
        {
            return RedirectToAction("signin","f");
        }
        //etc
    }
}

and, assuming default routing, loginUrl would have the value "~/MySpecialLogin"

Upvotes: 1

Related Questions