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

标签 android asp.net-mvc iis

目标

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

其他两个问题( this onethis one )已经解决了这个问题,但答案非常简短,对我毫无帮助。之前我不得不通过敲打我的电脑并盲目地更改每个设置直到某些东西起作用来解决这个问题。我不想再经历一次。我想了解这次我在做什么。

设置信息

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

我的应用程序属性中的 Web 选项卡设置为“使用本地 IIS Web 服务器”,并且我选中了“使用 IIS Express”。项目 url 是 http://localhost:25968/。我看到“本地主机”可能有问题,但是 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>

发生了什么

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

最佳答案

授予自己绑定(bind)到 localhost 和通配符网络适配器的权限,配置 IIS Express 以绑定(bind)到它们,并在防火墙上打开端口。通过使用通配符,您无需在 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"
    
  2. .vs\config\applicationhost.config 中(或者对于 VS2015 之前的版本,%USERPROFILE%\Documents\IISExpress\config\applicationhost.config) ,将通配符绑定(bind)添加到您的站点。结果应如下所示:

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

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

关于android - 在 Android 手机上调试 ASP.NET MVC 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13328090/

相关文章:

javascript - 在 URL 中传递 base64 信息作为查询字符串的正确方法?

iis - 如何找到网站对应的日志文件文件夹?

java - 使用倒计时器功能防止这种情况发生

android - Gradle不选择在lib文件夹下动态复制的库

c# - 自定义 html 帮助程序中的 css id

ajax - 以ajax形式编码特殊字符(asp mvc)

asp.net-mvc - 使用 IIS URL 重写将内容限制到两个域之一会导致重定向循环

powershell - 如何判断iisreset是否成功

android - com.android.internal.R.attr 和 android.R.attr 是否具有相同的值集?

android - 无法使用MaterialTextView