19

When using Nancy FX, I came across the following exception which was thrown when trying to fire up a web service: AutomaticUrlReservationCreationFailureException

Having looked into it in a bit more detail, I discovered that the way to fix this was to run up a cmd prompt (as an administrator), then run the following command:

netsh http add urlacl url=http://+:1234/ user=DOMAIN\username

where

  • DOMAIN\username is the id of the user the service will be run under
  • 1234 is the port that the service will be run on

I write this here in case anyone else comes across the same issue and spends a fruitless half hour or so looking for an answer - hopefully they will find this sooner than I did!

Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108
Charlie_
  • 193
  • 1
  • 1
  • 4
  • You should format this as a question and provide your own answer to it; this will help future users, especially if there are other solutions. – Nathaniel Ford Aug 21 '13 at 22:53

3 Answers3

18

If you're creating your own NancyFx host, it may be easier for you to flag your HostConfiguration this way

HostConfiguration hostConfigs = new HostConfiguration()
{
    UrlReservations = new UrlReservations() { CreateAutomatically = true }
};

or...

HostConfiguration hostConfigs = new HostConfiguration();
hostConfigs.UrlReservations.CreateAutomatically = true;

And then finally have something like

NancyHost nancyHost = new NancyHost(new Uri("http://+:80"), new DefaultNancyBootstrapper(), hostConfigs);
  • 3
    Does this require the Nancy service account to have local admin privileges? – tom redfern Aug 06 '15 at 10:18
  • I get with tat code : System.InvalidOperationException: Unable to configure namespace reservation at Nancy.Hosting.Self.NancyHost.StartListener() at Nancy.Hosting.Self.NancyHost.Start() – Arnaud Sep 11 '15 at 16:40
  • 1
    Ok, got it. It's because in French "Everyone" is "Tout le monde" with two spaces and that the command that Nancy launches does not protect the argument with quotes... Sot that method is not reliable for now, have to use netsh in a install program. – Arnaud Sep 11 '15 at 16:48
  • Exactly what I needed. Thanks! – Lachezar Lalov Jun 21 '18 at 14:22
  • Nancy throws me an exception if I try to use any wildcards for the Uri(). I'm using the Nancy.Hosting.Self.NancyHost() if that makes any difference? Anyone else get the same? – Dave Goodchild Jul 16 '18 at 15:02
16

The Message of the AutomaticUrlReservationCreationFailureException will tell you this

The Nancy self host was unable to start, as no namespace reservation existed for the provided url(s).

Please either enable CreateNamespaceReservations on the HostConfiguration provided to the NancyHost, or create the reservations manually with the (elevated) command(s):

http add urlacl url=http://+:8888/nancy/ user=Everyone
http add urlacl url=http://127.0.0.1:8888/nancy/ user=Everyone
http add urlacl url=http://+:8889/nancytoo/ user=Everyone

The suggested reservations is based on the base URIs that you pass into the host when you create it.

Karl Nicoll
  • 16,090
  • 3
  • 51
  • 65
TheCodeJunkie
  • 9,378
  • 7
  • 43
  • 54
  • Ah yes, see I should have looked a little harder at the error message - sorry for not spotting. I'm quite unfamiliar with network configuration tools so hadn't understood what the message meant. Thanks very much for the help in answering my question. – Charlie_ Aug 23 '13 at 22:36
  • 8
    This step does not seem necessary if I am creating my own web server using HttpListener - just curious why this would be needed for Nancy? – chrisb Aug 05 '14 at 05:26
11

The AutomaticUrlReservationCreationFailureException will also appear if you are running NancyFX from Visual Studio.

So make sure you are running as administrator in order for NancyFX to set up the underlying configurations

Björn Holdt
  • 326
  • 3
  • 5