Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self Hosting OWIN to other computers on the Network

I'm trying to self host an OWIN pipeline in a WinForms application. The pipeline is hosting up both static files and Web Api v2 content. The implementation is working great locally, but I'm not sure what I'm missing in order to be able to access the hosted files and APIs from remote machines on my network.

For simplicity sake, I downloaded the sample self-host app from codeplex here and tried accessing the test methods remotely after making the below modifications to the base address (I tried both running the netsh regisration and I'm running in Admin mode) and I still can't access them. What do I need to change in the configuration to be able to view the content from other computers on the same network?

static void Main()
{
    string baseAddress = "http://*:10281/";
    // Start OWIN host
    using (WebApp.Start<Startup>(url: baseAddress))
    {
        // Create HttpCient and make a request to api/values
        HttpClient client = new HttpClient();

        HttpResponseMessage response = client.GetAsync("http://localhost:10281/api/values").Result;

        Console.WriteLine(response);
        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        Console.ReadLine(); // Keeps the host from disposing immediately
    }
}

Here's the Startup Configuration, pretty basic stuff:

public class Startup
{
     // This code configures Web API contained in the class Startup, which is additionally specified as the type parameter in WebApplication.Start
    public void Configuration(IAppBuilder appBuilder)
    {
        // Configure Web API for Self-Host
        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        appBuilder.UseWebApi(config);
    }
}
like image 671
Duck Jones Avatar asked Jul 20 '15 15:07

Duck Jones


People also ask

What is Owin self hosting?

Open Web Interface for . NET (OWIN) defines an abstraction between . NET web servers and web applications. OWIN decouples the web application from the server, which makes OWIN ideal for self-hosting a web application in your own process, outside of IIS.


1 Answers

That code looks fine and there's no reason it shouldn't work, especially if you can access the OWIN server locally.

There's two likely issues preventing network access. Either you need to add an Inbound Rule to Windows firewall for port 10281 (or temporarily disable any firewalls on the hosting computer), or your network is blocking the traffic somehow.

like image 119
Zephyr Avatar answered Sep 18 '22 00:09

Zephyr