简体   繁体   中英

MVC Authentication Redirect to a New site C# (Windows authentication)

I want to redirect a user to a whole new site if they fail to login. I cannot find a good location in the application life cycle to do this or how to do this in MVC.

In the past we just put it in the page_load.

In mvc I use a custom authorized attribute and it works fine and redirects to the default 401 page. But I want to redirect to a whole new url or site.

In your custom authorize class you can do something like this (this may be MVC 5 only, I don't see it here )

protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
    filterContext.Result = new RedirectResult("http:\\someurl")
}

if that isn't available you have access to the HttpContext in AuthorizeCore

RedirectResult is detailed on msdn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM