I have a ASP.NET MVC project, and I would like to have a different LoginUrl for different areas of the website. Depending on the area of the site, different types of credentials are entered.
http://host.com/widget/home
should redirect the user to http://host.com/widget/logon
.
http://host.com/admin/home
should redirect the user to http://host.com/admin/logon
.
So far, the best solution I have come up with, is to have Forms Auth loginUrl="~/Account/Logon" in the web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880"/>
</authentication>
In the controller for Account:
public ActionResult LogOn()
{
//redirect depending on the returnUrl?
string returnUrl = ControllerContext.Controller.ValueProvider["ReturnUrl"].AttemptedValue;
if (returnUrl.StartsWith("/widget"))
{
return Redirect(string.Format("/widget/Logon?ReturnUrl={0}", returnUrl));
}
if (returnUrl.StartsWith("/admin"))
{
return Redirect(string.Format("/admin/Logon?ReturnUrl={0}", returnUrl));
}
return View();
}
Is there a better way to do this?