在 Android 手机上调试 ASP.NET MVC 应用程序 [英] Debugging an ASP.NET MVC application on an Android phone

查看:40
本文介绍了在 Android 手机上调试 ASP.NET MVC 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标

我正在寻找使用我的 IP 地址作为 URL 来调试我的 ASP.NET MVC 4 应用程序的最简单的分步设置过程.我希望能够使用我的计算机的本地 IP 地址(例如 - http://192.168.1.109:25968).我在 Windows 7 上运行 Visual Studio 2012 RC.

I'm looking for the simplest-possible, step-by-step setup process for debugging my ASP.NET MVC 4 application using my IP address as the URL. I want to be able to access the application from my Android phone, which is connected to my local network via Wi-Fi, using my computer's local IP address (e.g. - http://192.168.1.109:25968). I'm running Visual Studio 2012 RC on Windows 7.

这个问题已经由另外两个问题(这个这个),但答案非常简短,根本没有帮助我.我以前不得不通过敲打我的计算机并无意识地更改每个设置直到某些事情起作用来解决此问题.我不想再经历那个了.我想了解我这次在做什么.

This question has been addressed by two other questions (this one, and this one), but the answers are extremely brief and aren't helping me at all. I've had to resolve this issue before by banging on my computer and mindlessly changing every setting until something worked. I don't want to have to go through that again. I want to understand what I'm doing this time.

设置信息

该项目只是一个默认的 ASP.NET MVC 4 Internet 应用程序.我很确定我还没有改变任何东西.

The project is just a default ASP.NET MVC 4 Internet Application. I'm pretty sure I haven't changed anything yet.

我的应用程序属性中的 Web 选项卡设置为使用本地 IIS Web 服务器",并且我选中了使用 IIS Express".项目 url 是 http://localhost:25968/.我看到locahost"可能有问题,但 VS 不会让我输入 IP 地址或通配符.

The Web tab in my application's Properties is set to "Use Local IIS Web Server", and I have "Use IIS Express" checked. The Project url is http://localhost:25968/. I see that the "locahost" there might be a problem, but VS won't let me put in an IP address or wild cards.

我的应用程序的 IIS Express applicationhost.config 文件如下.

My IIS Express applicationhost.config file for my application are as follows.

<site name="APPLICATION_NAME" id="13">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:UsersUSERNAMEDocumentsVisual Studio 11ProjectsAPPLICATION_NAME" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:25968:localhost" />
    </bindings>
</site>

发生了什么

当我使用 http://localhost:25968 从主机连接到站点时,它运行良好.如果我尝试从主机使用 http://192.168.1.109:25968,我会收到错误请求 - 主机名无效,HTTP 错误 400.请求主机名无效."使用来自网络上另一台计算机的相同 URL,它只是超时.

When I connect to the site from the host computer with http://localhost:25968 it works great. If I try to use http://192.168.1.109:25968 from the host computer, I get "Bad Request - Invalid Hostname, HTTP Error 400. The request hostname is invalid." Using this same URL from another computer on the network, it just times out.

推荐答案

授予自己绑定到本地主机和通配符网络适配器的权限,配置 IIS Express 以绑定到它们,并打开防火墙上的端口.通过使用通配符,您无需在 IP 地址更改时重新配置.

Grant yourself permission to bind to both localhost and wildcard network adapters, configure IIS Express to bind to them, and open the port on your firewall. By using a wildcard, you don't have to reconfigure when your IP address changes.

步骤详细信息:(他们假设端口号为 5555 - 请改用您的实际端口)

Step details: (they assume a port number of 5555 - use your actual port instead)

  1. 以管理员身份从命令提示符运行这些命令:

  1. Run these commands from a command prompt as Administrator:

netsh http add urlacl url=http://localhost:5555/ user="NT AUTHORITYINTERACTIVE"
netsh http add urlacl url=http://*:5555/ user="NT AUTHORITYINTERACTIVE"

  • .vsconfigapplicationhost.config 中(或者对于 VS2015 之前的版本,%USERPROFILE%DocumentsIISExpressconfigapplicationhost.config), 向您的站点添加通配符绑定.结果应该是这样的:

  • In .vsconfigapplicationhost.config (or for pre-VS2015, %USERPROFILE%DocumentsIISExpressconfigapplicationhost.config), add a wildcard binding to your site. The result should look like this:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:localhost" />
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>
    

  • 为您的 IIS Express 站点打开防火墙端口.您可以从管理命令提示符执行此操作:

  • Open the firewall port for your IIS Express site. You can do this from an administrative command prompt:

    netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=5555 profile=private remoteip=localsubnet action=allow
    

  • 这篇关于在 Android 手机上调试 ASP.NET MVC 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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