首页 > 解决方案 > 从 IP 地址远程访问本地 ASP.NET Core 应用程序?

问题描述

我想从远程计算机或移动设备(调用)调试我的 asp.net 核心应用程序?请帮我。在标准 .net 中,.vs\config\applicationhost.config在更改<binding protocol="http" bindingInformation="*:21918:localhost" /><binding protocol="http" bindingInformation="*:21918:*" /> 工作时添加此代码。

           <site name="project" id="2">
                <application path="/" applicationPool="Clr4IntegratedAppPool">
                    <virtualDirectory path="/" physicalPath="F:\users\Api" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:21918:*" /> 
                </bindings>
            </site>

标签: asp.net-mvcvisual-studioapimodel-view-controller

解决方案


您可以使用此方法:

在您的项目中打开 Program.cs:

        var configuration = new ConfigurationBuilder()
            .AddCommandLine(args)
            .Build();


        var hostUrl = configuration["hosturl"]; // add this line
        if (string.IsNullOrEmpty(hostUrl)) // add this line
            hostUrl = "http://0.0.0.0:5001"; // add this line


        var host = new WebHostBuilder()
            .UseKestrel()
            .UseUrls(hostUrl)   // // add this line
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseConfiguration(configuration)
            .Build();

        host.Run();

更多信息


推荐阅读