LAN Access to.NET Projects

As we have already established.The NET project is hosted on localhost. We can’t get to it from any device on the same network.

Today, I’ll show you how to connect to your.NET project through LAN.

In Visual Studio, create a Web Application.
Create a Simple Endpoint now. I made a CalculatorController controller and an endpoint that returns the sum of two numbers.

[Route("Calculator/Sum")] [HttpGet] public async Task<HttpResponseMessage> Sum(int num1,int num2)
{
return Request.CreateResponse(HttpStatusCode.OK,(num1+num2));
}

Let’s get this project started. My project is accessible at https://localhost:44367/.Let me hit the endpoint to see whether it’s functioning on localhost, and then we can proceed.

Now, let’s move toward the configurations of how can we access the website through LAN. Just open the BaseDirectory of your Project, then Go to .vs/{ProjectName}/Config, and now open application host.config file.

Just add a new binding which will bind to your IP address.

<binding protocol=”http” bindingInformation=”*:50745:{youripaddress}" />

6. Close the Visual Studio, Run the Visual Studio as an administrator, then build and run the project. Access your endpoint through your IP address it will work.

7. If you are not able to access the project through any other device in the network. You just have to go to the Windows Defender firewall and add an inbound rule for the port on which the project is running.