为什么Kestrel不侦听指定的端口? [英] Why Kestrel doesn't listen at specified port?

查看:273
本文介绍了为什么Kestrel不侦听指定的端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用kestrel创建Web应用程序.在本文中 https://docs.microsoft .com/pl-pl/aspnet/core/fundamentals/servers/kestrel?tabs = aspnetcore2x 这里有解释如何使用kestrel的方法(以下代码):

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在端口49950上默认启动,但是在端口5000上没有监听.为什么它不起作用?我想念什么吗?我想强迫红est仅从代码中侦听5000条(不会干扰其他项目文件).另外,由于缺少SSL支持,UseUrls也不可接受.我怎样才能做到这一点?

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?

推荐答案

Kestrel是应用程序使用的端口. IIS Express充当一种反向代理.

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

如果要访问kestrel配置的端口,则必须将其作为控制台应用程序启动.单击开始按钮旁边的下拉按钮,然后选择YourCompany.YourApplication.Mvc(或任何名为您的项目的名称),而不是"IIS Express".然后单击开始",应用程序启动,并出现一个控制台窗口.

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.

如果您仍然想使用IIS-Express(因为您希望将其托管在IIS上并希望获得更深入的体验),请转到项目属性,选择调试"选项卡,选择"IIS Express"配置文件在下拉菜单中,然后更改应用程序URL".这将使用新端口更新launchSettings.json文件和IIS Express配置(.vs/config/applicationhost.config).

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.

强烈建议您不要手动编辑launchSettings.json文件,因为这可能会使applicationhost.config保持不变(这实际上决定了端口,launchSettings.json只是告诉IDE在浏览器中打开哪个URL).

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).

如果由于某种原因您在launchSettings.json/applicationhost.config中的URL不同步,则可以手动编辑applicationhost.config或将其删除(.vs文件夹通常是隐藏的,您可能必须显示为隐藏文件夹中),它将在下次打开该解决方案和/或运行该应用程序时重新创建.

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.

这篇关于为什么Kestrel不侦听指定的端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆