Nancy Can't Load Using URL Reservation

I have a desktop application that hosts a NancyFX web server by itself. As a desktop application, we require that we allow dynamic IP addresses, so we registered the URL using a wildcard parameter with netsh, like so:

netsh http add urlacl url=http://+:1234/ user=Everyone

      

However, when this application is run under a non-administrator account, the following exception is thrown.

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

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

netsh http add urlacl url=http://192.168.1.90:1234/ user=Everyone

      

I've tried many combinations of wildcards, all with the same result. I also looked at registering the template when loading Nancy, but because of Nancy using Uri types, this was wrong.

I was under the assumption that by using wildcard registration, I registered whatever IP address would be used. But Nancy seems to need a specific IP registered.

I would really appreciate it if someone could tell me why registering templates won't work with Nancy or even better how to get it to work with Nancy.

+3


source to share


1 answer


Old question, but in case anyone comes across this, Nancy SelfHost allows you to automatically create Url reservations using the HostConfiguration object .

Then the URL is reserved automatically at startup.



//Nancy configuration
HostConfiguration hostConfig = new HostConfiguration()
{
    UrlReservations = new UrlReservations()
    {
        //create URL reservations automatically
        CreateAutomatically = true
    }
};

//Uri
Uri uri = new Uri("http://localhost:9999");

using (var host = new NancyHost(hostConfig, uri))
{
    host.Start();

    Console.WriteLine("Running self-hosted server ...");
    Console.WriteLine("Press [Enter] to close the application.");
    Console.ReadLine();
}

      

0


source







All Articles