Why Kestrel doesn't listen at specified port?

旧城冷巷雨未停 提交于 2019-12-22 18:44:37

问题


I am trying to create web application using kestrel. In this article https://docs.microsoft.com/pl-pl/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x there is explanation how to use kestrel (code below):

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .UseKestrel(options =>
    {
        options.Listen(IPAddress.Loopback, 5000);
    })
    .Build();

IIS starts default at port 49950 but nothing is listening on port 5000. Why it doesn't work? Am I missing something? I want to force kestrel to listen on 5000 from code only (without interfering into other project files). Also UseUrls is non-acceptable because of missing SSL support. How can I achieve this?


回答1:


Kestrel is the port used by the application. IIS Express serves as a kind of reverse proxy.

If you want to access the port configured by kestrel, you have to start it as console application. Click the drop-down button next to the start-button and select YourCompany.YourApplication.Mvc (or whatever your project is called) instead of "IIS Express". Then click start and the application start and an console window appears.

Save it and then start the application/debugging.

If you still want to use IIS-Express (because you want to host it on IIS and want closer experience to it), then go to the project properties, choose the "Debug" tab, select the "IIS Express" profile in the drop down and then change the "App URL". This will update the launchSettings.json file and the IIS Express config (.vs/config/applicationhost.config) with the new port.

I would strongly advice against manually editing the launchSettings.json file, as this may leave the applicationhost.config untouched (which really determines the port, launchSettings.json just tells the IDE which URL to open in the browser).

If for any reason your urls in launchSettings.json / applicationhost.config are out of sync, you can manually edit the applicationhost.config or just delete it (the .vs folder is typically hidden, you may have to show hidden folders in your explorer first) and it will be recreated on the next opening of the solution and/or running the application.



来源:https://stackoverflow.com/questions/49895258/why-kestrel-doesnt-listen-at-specified-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!