【问题标题】:Newly created .Net Core gives HTTP 400 using Windows Authentication新创建的 .Net Core 使用 Windows 身份验证提供 HTTP 400
【发布时间】:2018-05-01 07:12:25
【问题描述】:
【问题讨论】:
标签:
c#
.net-core
windows-authentication
http-status-code-400
【解决方案1】:
启动应用程序后,您将在输出窗口中看到:
XYZ.API.Core> 内容根路径:C:\XYZ.API.Core> 正在监听:http://localhost:29002
XYZ.API.Core> 应用程序已启动。按 Ctrl+C 关闭。
XYZ.API.Core> 失败:Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware[0]
XYZ.API.Core>“MS-ASPNETCORE-TOKEN”与预期的配对令牌“de80437e-f80d-4f7f-b2b0-60f3bc81e9b0”不匹配,请求被拒绝。
因此,您浏览到 http://localhost:29002 并收到 HTTP 400 错误。原因是因为那是 Windows Authenticated 的错误 url。
打开 Properties > launchSettings.json 文件并注意 IIS 设置和应用程序 Url 使用不同的端口:
{ "iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:55403/",
"sslPort": 0
}
浏览到launchSettings文件中指定的applicationUrl,例如http://localhost:55403/api/values会返回预期的json。