从 IP 地址远程访问本地 ASP.NET Core 应用程序?

Ahm*_*deh 2 api model-view-controller asp.net-mvc visual-studio

我想从远程计算机或移动设备(调用)调试我的 ASP.NET Core 应用程序?请帮我。在标准 .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>
Run Code Online (Sandbox Code Playgroud)

Ahm*_*deh 5

你可以使用这个方法:

在您的项目中打开 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();
Run Code Online (Sandbox Code Playgroud)

更多信息