Self hosted OWIN and urlacl
Asked Answered
M

3

29

I've created a self hosted Nancy/SignalR application self-hosted in OWIN using Microsoft.Owin.Host.HttpListener and Microsoft.Owin.Hosting

Things work perfectly fine locally but as soon as I try to use anything but localhost to access the app I get a HTTP Error 503. The service is unavailable error. I can't even access the app using 127.0.0.1 or the machine name.

I've tried adding the port to urlacl using

http add urlacl http://*:8989/ user=EVERYONE but doesn't seem to do anything.

here are the OWIN start options that I've tried,

var options = new StartOptions
{
    Url = "127.0.0.1",
    App = GetType().AssemblyQualifiedName,
    Port = _configFileProvider.Port
};

var options = new StartOptions
{
    App = GetType().AssemblyQualifiedName,
    Port = _configFileProvider.Port
};

Here is the source code for the file that starts and stops the server.

Marchesa answered 20/5, 2013 at 4:32 Comment(6)
What url did you use in your code?Smacking
@dfowler updated the question with actual code.Marchesa
Try changing Url to "*" instead of binding to 127.0.0.1 only.Smacking
Your urlacl should also be + not * afaikEchevarria
@stevenrobins when I use + it won't even work for localhostMarchesa
@dfowler tried "*" doesn't seem to help.Marchesa
M
29

so it turns out you need to pass in a url into StartOptions in the same format as the urlacl.

Changing the start options to the code below fixed the problem. now the app is accessible across the network.

  var options = new StartOptions("http://*:8989")
  {
      ServerFactory = "Microsoft.Owin.Host.HttpListener"
  };
Marchesa answered 21/5, 2013 at 2:53 Comment(6)
How does this need to be adapted for SignalR 2 beta? Url and App are not properties of StartOptions as it shows for me.Luong
@uosɐſupdated sample code to match the syntax for current version of owin (1.1.0 beta 2)Marchesa
Wow. Very very useful :) So many other similar answers out there (mostly talking about IIS Express) but this one actually works.Zero
And, actually, you don't want to reserve ports with urlacl. #22293945 has some more information.Zero
In the end, what worked for me on Server 2012 and Windows 8.1 was to use http://+:9000 (with no urlacls set) and have the port open (on the domain in my case).Zero
I've been working on this for the past two days and I was so frustrated I wanted to stab a puppy. thank you!Nepean
E
12

I spend many hours solving similar issue on Windows 8.1.

    StartOptions options = new StartOptions();

    options.Urls.Add("http://localhost:9000");
    options.Urls.Add("http://127.0.0.1:9000");
    options.Urls.Add("http://192.168.0.102:9000");
    options.Urls.Add(string.Format("http://{0}:9000", Environment.MachineName));

    WebApp.Start<Startup>(options);

I could not listen or was getting 503 error...

If you want to listen on several IP addresses, each address needs its own urlacl record:

Does NOT work:

    netsh http>add urlacl http://+:9000/ user=EveryOne    

OK:

    netsh http>add urlacl http://localhost:9000/ user=EveryOne
    netsh http>add urlacl http://127.0.0.1:9000/ user=EveryOne
    etc.

After adding reservation for each address individually, everything works fine.

Emery answered 12/8, 2014 at 13:21 Comment(1)
Adding several IP addresses or URL's also works with new StartOption("http://*:9000/") on Microsoft.Owin.Hosting 3.0.1. and netsh http> add urlacl http://*:9000/, or run your app as admin.Tindal
C
9

Thanks to the info that @kay.one provided I was able to access my self-hosted Web API 2.2 (OWIN/Katana, console app) from the same machine via IP address. However just consolidate it into a simple step-by-step:

  1. In Main of Program.cs (for console app): WebApp.Start<Startup>("http://*:8080");
  2. From Windows Command Prompt (run as Administrator) enter netsh http add urlacl http://*:8080/ user=EVERYONE
  3. Go to Windows Firewall with Advanced Security and add an Inbound Rule that opens up TCP port 8080

You should then be able to access from another machine using IP address or computer name.

Disclaimer: I'm not a security expert so I don't know the security implications of doing this.

Cymogene answered 7/6, 2016 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.