在Android手机上调试ASP.NET MVC应用程序

Log*_*acy 16 iis asp.net-mvc android

目的

我正在寻找使用我的IP地址作为URL来调试我的ASP.NET MVC 4应用程序的最简单的逐步设置过程.我希望能够通过我的Android手机访问该应用程序,该手机通过Wi-Fi连接到我的本地网络,使用我的计算机的本地IP地址(例如 - http://192.168.1.109:25968).我在Windows 7上运行Visual Studio 2012 RC.

这个问题已经被另外两个问题(这个问题和这个问题)解决了,但答案非常简短,根本没有帮助我.我之前必须通过敲打我的电脑并盲目地改变每个设置来解决这个问题,直到有效.我不想再经历那次.我想了解这次我在做什么.

设置信息

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

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

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

<site name="APPLICATION_NAME" id="13">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\USERNAME\Documents\Visual Studio 11\Projects\APPLICATION_NAME" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:25968:localhost" />
    </bindings>
</site>
Run Code Online (Sandbox Code Playgroud)

发生了什么

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

Edw*_*rey 20

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

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

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

    netsh http add urlacl url=http://localhost:5555/ user="NT AUTHORITY\INTERACTIVE"
    netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"
    
    Run Code Online (Sandbox Code Playgroud)
  2. .vs\config\applicationhost.config中(或对于VS2015之前的版本,%USERPROFILE%\ Documents\IISExpress\config\applicationhost.config),请为您的站点添加通配符绑定.结果应如下所示:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:localhost" />
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 打开IIS Express站点的防火墙端口.您可以从管理命令提示符执行此操作:

    netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=5555 profile=private remoteip=localsubnet action=allow
    
    Run Code Online (Sandbox Code Playgroud)


cfe*_*uke 5

试一试:

netsh http add urlacl url=http://192.168.1.109:25968/ user=everyone
Run Code Online (Sandbox Code Playgroud)

来自:http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

您可以将计算机的主机名替换为IP地址,这样每次IP更改时都不必重新运行.