我有一个自我托管NancyFX Web服务器的桌面应用程序。作为桌面应用程序,要求我们允许动态IP地址,因此我们已使用netsh使用通配符选项注册了url,如下所示:

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


但是,当此应用程序以非管理员帐户运行时,将引发以下异常。

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


我尝试了通配符注册的许多组合,所有结果均相同。我还查看了在加载Nancy时注册通配符的方法,但是由于Nancy使用Uri类型,因此无效。

我以为通过使用通配符注册,我已经注册了要使用的任何IP地址。但是南希似乎需要注册特定的IP地址。

如果有人能告诉我为什么通配符注册不适用于Nancy,或者甚至更好,如何使其与Nancy一起使用,我将不胜感激。

最佳答案

一个老问题,但是如果有人遇到这个问题,Nancy SelfHost允许您使用HostConfiguration对象自动创建Url保留。

然后在启动时自动保留Url。

//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();
}

关于wildcard - Nancy无法加载通配符URL保留,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25498900/

10-13 04:38