Reputation: 4427
I have an application that implements single sign on (SSO). The url to login is this (https://sso.myced.com/SSOLogin.aspx?ReturnUrl=http://localhost:14877/Home) . The returnurl will be the url to the application i'm building (localhost:14877/Home). I have the [Authorize] attribute on my controller,
[Authorize]
public class HomeController : Controller
and when the user tries to access my app, they will be redirected to the sso url, login, and be redirected back to my app.
By default, MVC redirects to the Account controller and the login action. How do i tell MVC i want to go to my custom url and not "~/Account/Login"?
Upvotes: 1
Views: 2553
Reputation: 5075
Write a custom Authorize attribute and use it instead of Authorize. Something like this:
public class CustomAuthorize : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return /*Chech if user is loged in*/
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.HttpContext.Response.Redirect(URL TO REDIRECT);
}
}
Then use it on a controller:
[CustomAuthorize ]
public class HomeController : Controller
Upvotes: 3