【问题标题】:ASP.NET Web API with Windows Authentication lacks header WWW-Authenticate in response带有 Windows 身份验证的 ASP.NET Web API 在响应中缺少标头 WWW-Authenticate
【发布时间】:2019-01-04 13:57:44
【问题描述】:

我了解,对于安全请求,客户端首先执行匿名请求,获得 401 响应和 WWW-Authenticate 标头,然后使用收到的身份验证系统重试。

现在,我有以下代码:(如果缺少某些内容,请告诉我)

web.config:

<system.web>
  <compilation debug="true" targetFramework="4.6.1" />
  <httpRuntime targetFramework="4.6.1" />
  <authentication mode="Windows"/>
</system.web>

Controller.cs:

[Authorize]
public class FunctionalLocationsController : ApiController
{
  // ..
}

WebApiConfig:

config.EnableCors(new EnableCorsAttribute("*", "*", "*")
{
    SupportsCredentials = true
});
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });

请求(提琴手):

GET http://localhost/MADI.Backend.WebApi/api/functionallocations HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: en-GB,en;q=0.5
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: localhost
Connection: Keep-Alive

响应标头:

HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Fri, 04 Jan 2019 13:44:17 GMT
Content-Length: 6084

响应还包含有关 401 的 Html 人工消息。

有人知道为什么它不返回 WWW-Authenticate 标头吗?

谢谢

【问题讨论】:

    标签: asp.net security


    【解决方案1】:

    唉...我在这里发帖 10 分钟后自己发现了...

    Windows Integrated Security 是您需要在 Windows 功能中明确启用的功能。

    我认为&lt;authentication mode="Windows"/&gt; 启用了它,但只有在安装它时才会出现这种情况。否则它会默默地什么都不做(据我所知)。

    现在可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 2016-03-21
      • 1970-01-01
      • 2015-08-12
      • 2015-12-25
      相关资源
      最近更新 更多