从移动设备访问本地主机上托管的ASP.NET Core 2.1 Web应用 [英] Access ASP.NET Core 2.1 web app hosted on localhost from mobile device
问题描述
我用react创建了一个现成的asp.net core 2.1 Web应用程序. 当我运行它时,它托管在localhost :(某些端口)上. 我想在我的移动设备上访问它.
I create an out of the box asp.net core 2.1 web app with react. When I run it, it hosts on localhost:(some port). I want to access that on my mobile device.
我试图通过将端口添加到Windows Defender防火墙上的入站规则来从本地主机访问它,但是它没有用,所以我想将IP地址更改为0.0.0.0 :(某些端口)或将其托管在通过使用UseUrls方法更改lauchSettings.json和Program.cs我的本地IPv4地址.它没有用,给我一个错误,该应用程序无法运行. 我尝试使用我从Google询问我的IP地址"获得的外部IP地址,但也无济于事.
I tried accessing it from local host by adding the port to the Inbound Rules on Windows Defender Firewall.It didn't work so I wanted to change the ip address to 0.0.0.0:(some port) or to host it on my local IPv4 address by changing the lauchSettings.json and Program.cs by .UseUrls method.It didn't work, gave me an error that the app cannot run. I tried using my external IP address which I got from asking "My ip address" in google but that didn't help as well.
推荐答案
我使用它,也许可以帮忙
I use this, maybe it can help
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("https://*:5566")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
确保在防火墙中启用端口5566.通过电话访问 https://your_comp_ip_address:5566/即可. 将your_comp_ip_address更改为您的计算机ip地址,您可以从CMD进行检查.只需在CMD中运行'ipconfig'
Make sure to enable the port 5566 in firewall. From the phone access https://your_comp_ip_address:5566/ it should work. Change your_comp_ip_address to your computer ip address, you can check it from the CMD. Just run 'ipconfig' in the CMD
从Visual Studio中运行应用程序本身,而不是IIS Express,从下拉列表中选择AppName,然后按F5.请在下面检查所有这些照片:
From Visual Studio, run the App itself, not IIS Express, select AppNamefrom the drop down, then press F5. Kindly Check all of these photos below:
https://*:5566>
https://*:5566">
这篇关于从移动设备访问本地主机上托管的ASP.NET Core 2.1 Web应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!