【问题标题】:Nancy cannot load with wildcard url reservationsNancy 无法加载通配符 url 保留
【发布时间】:2014-08-26 05:46:56
【问题描述】:

我有一个自托管 NancyFX 网络服务器的桌面应用程序。作为桌面应用程序,我们需要允许动态 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 地址。但是Nancy好像需要注册具体的ip地址。

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

【问题讨论】:

  • 据我所知,这是一个 .NET 问题。尝试使用 nowin nuget.org/packages/Nowin 使用 Owin 进行托管,这解决了我在没有管理员权限的情况下自行托管的问题。
  • 谢谢 Phill,我会试试 Owin。

标签: wildcard nancy netsh


【解决方案1】:

一个老问题,但如果有人遇到这个问题,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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 2014-09-18
    • 1970-01-01
    • 2015-03-10
    相关资源
    最近更新 更多