gpt4 book ai didi

c# - 从移动设备访问本地主机上托管的 ASP.NET Core 2.1 Web 应用程序

转载 作者:行者123 更新时间:2023-11-30 13:43:40 25 4
gpt4 key购买 nike

我用 React 创建了一个开箱即用的 asp.net core 2.1 网络应用程序。当我运行它时,它托管在本地主机上:(某个端口)。我想在我的移动设备上访问它。

我尝试通过将端口添加到 Windows Defender 防火墙上的入站规则来从本地主机访问它。它没有用,所以我想将 ip 地址更改为 0.0.0.0:(某个端口)或将其托管在我的通过 .UseUrls 方法更改 lauchSettings.json 和 Program.cs 来获取本地 IPv4 地址。它没有用,给我一个应用程序无法运行的错误。我尝试使用我在 Google 中询问“我的 IP 地址”时获得的外部 IP 地址,但这也没有帮助。

Picture of Program.cs file

Picture of lauchSettings.js

Error when changing lauchSettings.js

最佳答案

我用这个,也许它可以帮助

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("https://*:5566")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();

请注意,对于最新的 .Net,您可以在 launchSettings.json 文件中设置 URL,如下所示:

latest .Net version

确保在防火墙中启用端口 5566。从电话访问 https://your_comp_ip_address:5566/它应该可以工作。将 your_comp_ip_address 更改为您的计算机 ip 地址,您可以从 CMD 中查看它。只需在 CMD 中运行“ipconfig”

在 Visual Studio 中,运行应用程序本身,而不是 IIS Express,从下拉列表中选择 AppName,然后按 F5。请检查以下所有这些照片:

From The Drop Down, select the AppName to run it

Windows Firewall Ports, add a new Outbound Rule: Port, say give a range of 5560-5570

Check the IP address

Make sure when you run, a CMD is displayed, and check out the code https://*:5566

From your phone browser, enter the url correctly

And then, voila!!! Your Web App is running

关于c# - 从移动设备访问本地主机上托管的 ASP.NET Core 2.1 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53364145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com