0
votes

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"?

1
You got the right answer from @Stralos, but I'm curious... once the user is authenticated in myced.com, how will your app know that it is ok to let the user in? - Eddie Paz
Its being taken care of in the ssologin project..i got this to work - BoundForGlory

1 Answers

2
votes

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