从网络上的另一台电脑访问 ASP.NET 开发服务器

发布于 2024-08-11 23:02:14 字数 338 浏览 9 评论 0原文

我想在其他浏览器中测试我的网络应用程序。我已经安装了 Virtual PC 来做到这一点。 ASP.NET 开发服务器不允许远程连接,因此虚拟 PC(网络上的另一台计算机)无法访问该网站。

我发现 这篇 帖子已经开始,但没有解决方案。

我知道使用 localhost 是行不通的。我听说过使用机器 IP,但是如何获得正确的 IP?看看我的lynksys路由器管理员?

如果我要获取我的 IP,我确信 asp.net 开发服务器不允许远程连接。我怎样才能让它这样做?

I would like to test my web app in other browsers. I have installed Virtual PC to do just that. the ASP.NET development server does not allow remote connections so the virtual pc (another computer on the network) cannot access the website.

I found this post that was started but there was no solution.

I understand that using localhost will not work. I heard about using the machines ip, but how do I get that correct ip? Look at my lynksys router admin?

If I were to get as far as getting my IP, im sure that the asp.net dev server does not allow remote connections. How do I enable it to do so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

ぶ宁プ宁ぶ 2024-08-18 23:02:14

答案是:(*)。即使打开 Windows 防火墙 TCP 端口,也无法从一台计算机上访问另一台计算机上的 ASP.NET 开发服务器。

来自 MSDN 文章 “Visual Web Developer 中的 Web 服务器

它是专门为在本地主机方案(从与 Web 服务器相同的计算机上进行浏览)下提供或运行 ASP.NET 网页而构建的。

换句话说,ASP.NET 开发服务器将为本地计算机上的浏览器请求提供页面。它不会向另一台计算机提供页面。此外,它不会提供应用程序范围之外的文件。

(*) 您必须从本地安装的 IIS 运行您的站点...或者使用此博客文章中描述的一些免费软件进行出色的修改:

iPhone 访问 Visual Studio ASP .NET开发服务器

使用SPI端口转发接受设备连接,执行以下操作:

将“本地端口”设置为设备将连接的端口号,出于习惯我通常使用8080
将“远程主机”设置为本地主机
将“远程端口”设置为 ASP.NET Dev Server 端口

单击“激活”按钮开始接受连接

(注意:确保您已使用管理员权限启动程序)

The answer is: no(*). You cannot access the ASP.NET Development Server on one machine from another, even if you open the Windows firewall TCP port.

From the MSDN article "Web Servers in Visual Web Developer":

It is specifically built to serve, or run, ASP.NET Web pages under the local host scenario (browsing from the same computer as the Web server).

In other words, the ASP.NET Development Server will serve pages to browser requests on the local computer. It will not serve pages to another computer. Additionally, it will not serve files that are outside of the application scope.

(*) You'll have to run your site from your locally installed IIS... or do the nice hack using some freeware described in this blog post:

iPhone Accessing the Visual Studio ASP.NET Development Server

Use SPI Port Forward to accept the device connections do the following:

Set "Local port" to the port number the device will connect on, I usually use 8080 out of habit
Set "Remote host" to localhost
Set "Remote port" to the ASP.NET Dev Server Port

Click the "Activate" button to start accepting connections

(note: make sure you've started the program with admin rights)

绳情 2024-08-18 23:02:14

我在这里对您的设置进行了一些猜测,因此请耐心等待:

如果您的虚拟机是 XP Professional、Vista Business、Windows 7 Professional 或更高版本,那么您应该能够在开发计算机上本地运行 IIS 并从另一台计算机访问该 Web 服务器通过虚拟机名称位于同一网络的计算机。

同样,如果您在真机上进行开发并希望使用不同的虚拟机来访问 Web 应用程序,则应确保已安装 IIS,在 IIS 中创建一个新网站,然后浏览到通过虚拟机中的计算机名称的 Web 应用程序。

无论哪种方式,都不要尝试使用 Visual Studio 中的内置 Web 服务器,只需将网站发布到 IIS 并以这种方式使用它即可。

祝你好运,希望这对一些人有帮助。

I'm making some guesses about your setup here so bear with:

If your virtual machine is XP Professional, Vista Business, Windows 7 Professional or better, then you should be able to run IIS locally on the development machine and access that webserver from another machine which is on the same network via the virtual machine's name.

Likewise, if you're doing development on a real machine and would like to use different virtual machines to access the web application, you should make sure that you have IIS installed, create a new website in IIS and you should be to browse to the web application via machine name from your virtual machines.

Either way, don't try to use the builtin web server from Visual Studio, just publish your site to IIS and work with it that way.

Good luck and hope this helps some.

情场扛把子 2024-08-18 23:02:14

使用 RINETD 设置端口转发
详细信息请参见:http://blog.waynehartman.com/articles/218.aspx

Setup a portforwarding using RINETD
Deatils here: http://blog.waynehartman.com/articles/218.aspx

心凉怎暖 2024-08-18 23:02:14

如果您不想使用 IIS(或隧道),另一个答案: https://stackoverflow.com/a/12008223/1552178< /a>

在主机上使用 fiddler 或类似工具 - 在客户端上设置浏览器
VM 要使用代理,然后像往常一样使用 localhost:dev_port
客户端。

来自客户端的所有请求都会转到您的开发计算机上的代理
路由到开发计算机上的 localhost 和 ASP.net 开发服务器
认为请求来自您的开发机器!

Another answer if you don't want to use IIS (or tunnels): https://stackoverflow.com/a/12008223/1552178

Use fiddler or similar on your host - set your browser on the client
VM to use the proxy then just use localhost:dev_port as usual on the
client.

All requests from the client goto the proxy on your dev machine which
routes to localhost on the dev machine and the ASP.net dev server
thinks the request is from your dev machine!

国产ˉ祖宗 2024-08-18 23:02:14

我回答这个老问题是为了帮助人们在没有 IIS 的情况下实现它。

1.第一步

您必须下载Fiddler

下载并安装 Fiddler 后,将其打开。

进入工具-> Fiddler 选项->连接选项卡->并选中“允许远程计算机连接”

在此处输入图像描述

重新启动 Fiddler。

2.第二步

此后,在网络上的另一台电脑或虚拟机中,打开 Internet Explorer->互联网选项->连接选项卡->局域网设置->选中“为您的 LAN 使用代理服务器” :

在此处输入图像描述

  1. 该地址是你的开发机器。
  2. 并将端口设置为 8888

现在,您可以从网络上的另一台 PC 访问 ASP.NET Web 服务器(也许您还有更多配置要做,例如防火墙、不受限制的端口等,但这是一个好的开始)!

要访问它-> http://localhost.:54814

  • 不要忘记“localhost”后面的附加点! (覆盖本地本地主机)
  • 端口“54814”在我的例子中是 ASP.NET Web 服务器端口。

注意:

  • 要测试代理是否工作,您可以尝试以下操作:http://localhost.:8888
  • 也许我忘记指出一些配置,但它总是取决于网络基础设施。

I am answering this old question to help people to make it work without IIS.

1. First Step

You have to download Fiddler.

Once Fiddler is downloaded and installed, open it.

Go in Tools-> Fiddler Option-> Connection tab-> And check "Allow remote computers to connect" :

enter image description here

Restart Fiddler.

2. Second Step

After this, in the other PC on the network OR the VM, open internet explorer-> Internet Options-> Connection Tab-> Lan Settings-> Check "Use a proxy server for your LAN" :

enter image description here

  1. The adress is the IP adress of your DEV machine.
  2. And put the port 8888

Now, you can access the ASP.NET Web Server from another PC on the network (maybe you have, more config to do, like firewall, unrestricted port, etc, but this is a good start) !

To access it -> http://localhost.:54814

  • Don't forget the additional point after "localhost" ! (Overwrite the local localhost)
  • The port, "54814" in my case, is the ASP.NET Web Server port.

NOTE :

  • To test if the proxy work, you can try this : http://localhost.:8888
  • Maybe I forgot to point out some configurations, but it always depend of the network infrastructure.
Hello爱情风 2024-08-18 23:02:14

适用于 Linux 的工作解决方案

如果您在 Windows 上的 VM 或另一台主机上运行 ASP.NET Dev Server,并且您希望从 Linux

上的 Windows 计算机上

访问它,那么这应该可以工作。由于某种原因,您无法直接连接到 ASP.NET开发服务器端口,需要先在本地代理:

使用SPI端口转发接受设备连接执行以下操作:

将“本地端口”设置为设备将连接的端口号,例如 8089
将“远程主机”设置为本地主机
将“远程端口”设置为 ASP.NET Dev Server 端口

单击“激活”按钮开始接受连接

(注意:确保您已使用管理员权限启动程序)

在 Linux 计算机上

本地转发本地主机端口 8089 到 Windows IP(将 GUEST_IP_HERE 替换为正确的 IP):

iptables -t nat -A OUTPUT -m addrtype --src-type LOCAL --dst-type LOCAL -p tcp --dport 8089 -j DNAT --to-destination GUEST_IP_HERE:8089
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE

这是必需的,因为开发服务器专门在请求中查找 localhost,并且不会响应 http://GUEST_IP_HERE :8089 来自主机

Working solution for Linux

This should work if you're running an ASP.NET Dev Server on Windows in a VM or on another host and you want to access it from Linux

On Windows machine

For some reason you cannot connect directly to the ASP.NET dev server port, you need to proxy it locally first:

Use SPI Port Forward to accept the device connections do the following:

Set "Local port" to the port number the device will connect on, such as 8089
Set "Remote host" to localhost
Set "Remote port" to the ASP.NET Dev Server Port

Click the "Activate" button to start accepting connections

(note: make sure you've started the program with admin rights)

On Linux machine

Locally forward localhost port 8089 to the windows IP (replace GUEST_IP_HERE with the correct ip):

iptables -t nat -A OUTPUT -m addrtype --src-type LOCAL --dst-type LOCAL -p tcp --dport 8089 -j DNAT --to-destination GUEST_IP_HERE:8089
iptables -t nat -A POSTROUTING -m addrtype --src-type LOCAL --dst-type UNICAST -j MASQUERADE

This is needed because the dev server specifically looks for localhost in the request and will not respond to http://GUEST_IP_HERE:8089 from the host

北座城市 2024-08-18 23:02:14

我尝试了以下操作,我希望启用当前的 .net 框架 [ core / x-platform ] 6.0 版本,提供至少从本地子网上的其他计算机进行 ASP.NET 开发 Web 服务器访问,无需使用任何第三方软件启用端口转发/代理到本地主机仅公开的 Web 服务器。

我能够从 windows wsl [适用于 linux 的 windows 子系统] 发行版会话启动 asp.net 开发 Web 服务器,并使用 Windows 主机 wi-fi 适配器 IP 地址访问它,但不能从子网上的另一台计算机(例如 vmware linux 安装)访问它以桥接模式运行。如果我将 vmware linux 安装切换到 nat 模式,它确实有效。

关于为什么这不允许其他主机按照我的预期进行访问的任何想法?

netsh interface portproxy add v4tov4 listenport=<tcp port for non-localhost access allowed/enabled in windows firewall> listenaddress=0.0.0.0 < or windows wired/wifi ipaddress > connectport=<tcp port for localhost access to asp.net development web server> connectaddress=localhost 

e.g. netsh interface portproxy add v4tov4 listenport=4430 listenaddress=0.0.0.0 connectport=7146 connectaddress=localhost & netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=5038 connectaddress=localhost 

netsh interface portproxy show all 

// for %i in ( 4430, 8080 ) do ( netsh interface portproxy delete v4tov4 listenport=%i listenaddress=0.0.0.0 )

netsh advfirewall firewall add rule name="Asp.Net Development Web Server Listeners to Expose" dir=in protocol=tcp localport=<csv list of tcp ports allowed/enabled in windows firewall> profile=private|any remoteip=localsubnet|any action=allow [ enable=yes ]

e.g. netsh advfirewall firewall add rule name="Asp.Net Development Web Server Listeners to Expose" dir=in protocol=tcp localport=4430,8080 profile=private remoteip=localsubnet action=allow

netsh advfirewall firewall show rule name="Asp.Net Development Web Server Listeners to Expose" [ or wf.msc | inbound rules ]

// netsh advfirewall firewall delete rule name="Asp.Net Development Web Server Listeners to Expose"

I tried the following that i expected to enable current .net framework [ core / x-platform ] 6.0 release provided asp.net development web server access at least from other machines on local subnet w/o needing to use any 3rd party software enable the port forwarding/proxy to localhost only exposed web server.

I was able to launch the asp.net development web server from windows wsl [ windows subsystem for linux ] distro session and access it using the windows host wi-fi adapter ip address but not from another machine on my subnet, e.g. a vmware linux install operating in bridge mode. It did work if i switched vmware linux install to nat mode.

Any thoughts on why this doesn't allow other hosts access as i expected it would?

netsh interface portproxy add v4tov4 listenport=<tcp port for non-localhost access allowed/enabled in windows firewall> listenaddress=0.0.0.0 < or windows wired/wifi ipaddress > connectport=<tcp port for localhost access to asp.net development web server> connectaddress=localhost 

e.g. netsh interface portproxy add v4tov4 listenport=4430 listenaddress=0.0.0.0 connectport=7146 connectaddress=localhost & netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=5038 connectaddress=localhost 

netsh interface portproxy show all 

// for %i in ( 4430, 8080 ) do ( netsh interface portproxy delete v4tov4 listenport=%i listenaddress=0.0.0.0 )

netsh advfirewall firewall add rule name="Asp.Net Development Web Server Listeners to Expose" dir=in protocol=tcp localport=<csv list of tcp ports allowed/enabled in windows firewall> profile=private|any remoteip=localsubnet|any action=allow [ enable=yes ]

e.g. netsh advfirewall firewall add rule name="Asp.Net Development Web Server Listeners to Expose" dir=in protocol=tcp localport=4430,8080 profile=private remoteip=localsubnet action=allow

netsh advfirewall firewall show rule name="Asp.Net Development Web Server Listeners to Expose" [ or wf.msc | inbound rules ]

// netsh advfirewall firewall delete rule name="Asp.Net Development Web Server Listeners to Expose"
月寒剑心 2024-08-18 23:02:14

2022 年:

在 ASP.NET Core .NET 6 方面尝试一切并失败后,我发现
https://mitmproxy.org/

mitmproxy --mode reverse:https://localhost:7053 --ssl-insecure

涵盖了我的用例。

在手机和其他设备上通过 http://{your-pc-ip}:8080 访问

year 2022:

After trying everything on asp.net core .NET 6 side and failed I have found
https://mitmproxy.org/

mitmproxy --mode reverse:https://localhost:7053 --ssl-insecure

covers my use case.

on phone and other devices access with http://{your-pc-ip}:8080

╰ゝ天使的微笑 2024-08-18 23:02:14

打开命令提示符并键入; “ipconfig”这将为您提供机器的 IP 地址。

如果禁用防火墙(至少对于 asp.net 开发端口),您应该能够在虚拟 PC 的浏览器中输入 http://192.168.1.3:3243/default.aspx

Open a command prompt and type; "ipconfig" this will give you your machines IP address.

If you disable your firewall (for the asp.net dev port at least) you should be able to type into the virtual PC's browser http://192.168.1.3:3243/default.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文