【发布时间】: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 标头吗?
谢谢
【问题讨论】: