.NET Core 外部访问站点? [英] .NET Core Access Site Externally?

查看:29
本文介绍了.NET Core 外部访问站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在调试模式下使用 Kestrel 在 VS 2019 中启动我的 .NET Core 应用程序时,我只能以 https://localhost:5001 访问.当我尝试用我的计算机的 fqdn 替换 localhost 时,我收到无法访问站点".所以实际上它是计算机和域名,所以 https://win7.int.com:5001.我想这样做,以便我可以从不同的机器访问该站点.如果它在我自己的机器上不起作用,我怀疑它会在另一台机器上运行.现在理想情况下,我会在这个主页下有几个应用程序(如 app1、app2 等).URL 将是 https://win7.int.com/app1:5001https://win7.int.com/app2:5001 等等.

When I start my .NET Core app in VS 2019 using Kestrel in debug mode I can only access as https:// localhost:5001. When I try to replace localhost with my fqdn of my computer I get "Site cannot be reached". So actually it would be the computer and domain name so https:// win7.int.com:5001. I want to do this so that I can access the site from a different machine. If it doesn't work on my own machine this way I doubt it would on another. Now ideally I would have several apps under this main page (like app1, app2, etc.). URLs would be https:// win7.int.com/app1:5001 and https:// win7.int.com/app2:5001 and so on and so forth.

对不起,我有 grails 背景,当应用程序在 localhost 上启动时,我可以用我的计算机名称替换 localhost 并且它可以工作.在不通过 IIS 的情况下,我需要做什么才能在 .NET Core 中完成这项工作?想使用 Kestrel.

Excuse me I have a grails background and when an app starts on localhost I can just replace localhost with my computer name and it works. What do I need to do to make this work in .NET Core without going through IIS? Want to use Kestrel.

推荐答案

默认情况下 Kestrel 只绑定到 http://localhost:5000https://localhost:5001

By default Kestrel only binds to http://localhost:5000 and https://localhost:5001

如果您想更改此设置,您可以使用 UseUrls 方法使用端口和协议配置 IP 地址或主机地址,以便服务器侦听请求:

If you want to change this you can configure the IP addresses or host addresses with ports and protocols that the server should listen on for requests by using the UseUrls method:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).UseKestrel().UseUrls("http://*:5000;https://*:5001")
.UseStartup<Startup>();

这篇关于.NET Core 外部访问站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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