Я добавил строку .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
Можно ли использовать 'UseUrls()' перед 'UseIISIntegration()'. см. http://stackoverflow.com/questions/37862475/specifying-the-url-port-that-a-asp-net-core-1-0-webapi-exe-should-use-in-progr –
Пожалуйста, подтвердите, если вы запускали это внутри IIS, IISExpress или автономно. –
Я переместил 'UseUrls()' перед 'UseIISIntegration()' и работает, когда debug запускает имя приложения. Это все еще не работает, если вы запускаете с помощью IIS express. – ca9163d9