web apiにアクセスする他のホストのクライアントを有効にするために、.UseUrls("http://*:5000")
行を追加しました。ポート番号を変更した後でVisual Studioでデバッグできませんか?
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()
は本番用にのみコンパイルする必要がありますか?
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:Information: Request starting HTTP/1.1 GET http://localhost:5000/api/Test
Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware:Error: 'MS-ASPNETCORE-TOKEN' does not match the expected pairing token '9bca37f2-7eda-4517-9f8f-60b6cc05cf01', request rejected.
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 8.5976ms 400
UseIISIntegration()の前に 'UseUrls()'を呼び出すことができますか? http://stackoverflow.com/questions/37862475/specifying-the-url-port-that-a-asp-net-core-1-0-webapi-exe-should-use-in-progr –
をご確認ください。 IIS、IISExpress、またはスタンドアロンの内部でこれを実行していました。 –
'UseIISIntegration()'の前に 'UseUrls()'を移動し、デバッグ時にアプリケーション名を実行します。 IIS Expressで動作させてもまだ動作しません。 – ca9163d9