How to fix a AutomaticUrlReservationCreationFailureException when using Nancy FX Self Host
Asked Answered
I

3

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!

Incardinate answered 21/8, 2013 at 22:33 Comment(1)
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.Habiliment
F
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.

Fye answered 22/8, 2013 at 5:49 Comment(2)
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.Incardinate
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?Peterus
D
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);
Diehl answered 27/6, 2014 at 5:38 Comment(5)
Does this require the Nancy service account to have local admin privileges?Leanaleanard
I get with tat code : System.InvalidOperationException: Unable to configure namespace reservation at Nancy.Hosting.Self.NancyHost.StartListener() at Nancy.Hosting.Self.NancyHost.Start()Kepi
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.Kepi
Exactly what I needed. Thanks!Taddeusz
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?Prototrophic
F
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.

Fye answered 22/8, 2013 at 5:49 Comment(2)
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.Incardinate
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?Peterus
P
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

Pomeroy answered 9/3, 2016 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.