【发布时间】:2016-12-14 19:24:41
【问题描述】:
我添加了 .UseUrls("http://*:5000") 行,以使来自其他主机的客户端能够访问 web api。
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://*:5000") // Added
.Build();
host.Run();
}
但是,使用浏览器访问localhost:5000/api/Test得到HTTP/1.1 400 Bad Request的错误? .UseUrls() 是否应该只编译用于生产?
测试时从 Visual Studio 输出窗口复制以下消息。
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: 请求开始 HTTP/1.1 GET http://localhost:5000/api/Test
Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware:错误:“MS-ASPNETCORE-TOKEN”与预期的配对令牌“9bca37f2-7eda-4517-9f8f-60b6cc05cf01”不匹配,请求被拒绝。
Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求在 8.5976 毫秒内完成 400
【问题讨论】:
-
你能在
UseIISIntegration()之前打电话给UseUrls()吗?见stackoverflow.com/questions/37862475/… -
请确认您是在 IIS、IISExpress 中运行它还是独立运行。
-
我将
UseUrls()移到UseIISIntegration()前面,它在调试运行应用程序名称时有效。如果使用 IIS express 运行,它仍然不起作用。 -
即使在那之后仍然是相同的异常或另一个?
标签: asp.net-core asp.net-core-mvc .net-core