Ahmad Aghazadeh
Ahmad Aghazadeh

Reputation: 17131

Remote Access to Local ASP.NET Core Applications From IP Address?

I want to (call)debug my asp.net core application from remote computer or mobile device? please help me. In standard .net add this code in .vs\config\applicationhost.config when change <binding protocol="http" bindingInformation="*:21918:localhost" /> to <binding protocol="http" bindingInformation="*:21918:*" /> its worked.

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

Upvotes: 2

Views: 8397

Answers (4)

devmet34
devmet34

Reputation: 27

For .net core its very simple to access to your local web app running on VS from a remote device; just change applicationUrl values in launchsettings.json from "https://localhost:[port]" to "https://0.0.0.0:[port]" and similar for http binding.

If you have a firewall running on host machine, you might need to allow the port for remote access.

Upvotes: 0

Ahmad Aghazadeh
Ahmad Aghazadeh

Reputation: 17131

You can use this method:

Open Program.cs in your project:

        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();

More Info

Upvotes: 5

naim
naim

Reputation: 39

you can follow the instructions below on how to solve your problem and go through all these problems. 1- Be sure you don’t ave any open Visual Studio instance.

2- Open the file %userprofile%\Documenti\IISExpress\config\applicationhost.config , being %userprofile% your user folder – like C:\Users\YourUsername\.

3-Look for the entry corresponding to the web application we want to modify and change its binding element in the following way: <binding protocol="http" bindingInformation="*:<port>:*" /> All we need to do there is to replace a couple of localhost with *, leaving the automatically assigned <port> as it is. If you really need to change that port, replace it with another valid, free TCP port (like 8080) and perform the following step. Otherwise, skip it and go to the step next to it.

4-If you changed the automatically assigned TCP port you also need to open your web application project (.csproj) and solution (.sln) files and ensure there are no references to the previous port: they can be there or not depending on your choosen project type (Web Application, MVC App, Web Site, etc.). If that’s the case, replace the old port with the new one.

5-Open a Command Prompt (with Administrator permissions) and type the following: netsh http add urlacl url=http://*:<port>/ user=everyone Putting the application TCP port in place of . If you get an error messae (1789) it means that the Everyone user group is not present on your system, something who can occur in some Windows localizations. If that’s the case, just replace everyone with the corresponding user group name. Instead than doing this step you could also try and execute Visual Studio with administrator permissions.

6-Open Windows Firewall advanced configuration panel and add an inbound rule to enable the inbound traffic for the application IISExpress.exe OR for the TCP port used by your web application. If you disabled it for another product, do the same with it. If you ain’t using any – are you sure? – you can either take the chance to fill the void and then perform the above or just skip this step.

Once you did this you can launch Visual Studio and run your application in Debug or Release mode: you should be able to access it from any external, network-connected device using the following web address: http://<lan-ip-address>:<port>/

Upvotes: 2

Payam Khaninejad
Payam Khaninejad

Reputation: 7996

There is a tunneling solution for this situation, you can use ngrok app to tunnel you local env and give a remote URL to the outside of the network for debugging or testing purpose.

After downloading ngrok just run this command:

./ngrok http 25114 -host-header="localhost:25114"

Don't forget to replace your local app port.

Upvotes: 3

Related Questions