我添加了该行.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();
}
Run Code Online (Sandbox Code Playgroud)
但是,使用浏览器访问localhost:5000/api/Test得到了错误HTTP/1.1 400 Bad Request?应该.UseUrls()只编译生产吗?
HTTP/1.1 400 Bad Request Date: Mon, 08 Aug 2016 21:42:30 GMT Content-Length: 0 Server: Kestrel
测试时,从Visual Studio输出窗口复制以下消息.
Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求启动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.5976ms 400结束