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

标签 c# asp.net-core

我用 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/

相关文章:

asp.net-core - Fluent 验证在 Bootstrap 4 Modal 中不起作用

c# - GetOwinContext 在 ASP.NET Core 中不起作用

c# - 从 shell 元数据属性获取变形视频的显示大小

c# - 如何找到实现给定接口(interface)的所有类?

c# - 在 WCF 服务中发送具有从同一父级派生的不同类的对象列表

asp.net-core - “DevExpress.Blazor.DxDataGridColumn”没有与名称 'DisplayFormatString' 匹配的属性

c# - 如何在 Asp.net Core 运行时从 DependencyInjection 解析泛型类型服务

c# - 禁用 WPF DataGrid 上的行编辑

c# - 嵌套动态控件,使用自定义事件处理程序

c# - 如何发布包含 Iformfile 的 View 模型数组的表单?