有条件地禁用Windows身份验证

时间:2015-11-25 21:48:40

标签: asp.net iis asp.net-web-api windows-authentication

我有一个ASP.NET WebApi SaaS应用程序,用户可以选择执行HTTP基本身份验证或Windows身份验证。

我的控制器根据某些查询字符串值知道是否执行基本HTTP身份验证或Windows身份验证。

public class MyController : ApiController
{
    public IHttpActionResult Get(int id)
    {
        if (!User.Identity.IsAuthenticated)
        {
            if (id == 5) // do basic for this resource only
            {
                return new BasicAuthenticationChallenge();
            }

            return Unauthorized();
        }

        return Ok("hello world");
    }
}

我目前对BasicAuthenticationChallenge的实施只是返回401: UnauthorizedWWW-Authenticate: Basic realm="api"标题。

但是,由于启用了Windows身份验证,因此IIS决定附加NTLM和Negotiate标头,这会导致客户端无法理解响应。

... (response headers)
WWW-Authenticate: Basic realm="api"
WWW-Authenticate: NTLM
WWW-Authenticate: Negotiate
... (response headers)

在尝试进行基本身份验证时,如何让IIS停止向WebApi的401响应中添加标题?

0 个答案:

没有答案
相关问题