AD FS 2.0 Authentication and AJAX

后端 未结 7 1903
一向
一向 2020-12-30 05:58

I have a web site that is trying to call an MVC controller action on another web site. These sites are both setup as relying party trusts in AD FS 2.0. Everything authentica

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 06:06

    If you do not want to receive HTML with the link you can handle AuthorizationFailed on WSFederationAuthenticationModule and set RedirectToIdentityProvider to false on Ajax calls only.

    for example:

    FederatedAuthentication.WSFederationAuthenticationModule.AuthorizationFailed += (sender, e) =>
    {
        if (Context.Request.RequestContext.HttpContext.Request.IsAjaxRequest())
        {
            e.RedirectToIdentityProvider = false;
        }
    };
    

    This with Authorize attribute will return you status code 401 and if you want to have something different, then you can implement own Authorize attribute and write special code on Ajax Request.

提交回复
热议问题