【问题标题】:How to fix a AutomaticUrlReservationCreationFailureException when using Nancy FX Self Host使用 Nancyfx Self Host 时如何修复 AutomaticUrlReservationCreation 失败异常
【发布时间】:2013-08-21 22:33:51
【问题描述】:

在使用 Nancy FX 时,我遇到了以下尝试启动 Web 服务时引发的异常:AutomaticUrlReservationCreationFailureException

经过更详细的研究,我发现解决此问题的方法是运行 cmd 提示符(以管理员身份),然后运行以下命令:

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

在哪里

  • DOMAIN\username 是运行服务的用户 ID
  • 1234 是服务运行的端口

我在这里写这个,以防其他人遇到同样的问题并且花了半个小时左右毫无结果地寻找答案 - 希望他们会比我更快地找到这个!

【问题讨论】:

  • 您应该将其格式化为问题并提供您自己的答案;这将对未来的用户有所帮助,尤其是在有其他解决方案的情况下。

标签: nancy netsh


【解决方案1】:

如果您要创建自己的 NancyFx 主机,以这种方式标记您的 HostConfiguration 可能会更容易

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

或者...

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

然后终于有了类似的东西

NancyHost nancyHost = new NancyHost(new Uri("http://+:80"), new DefaultNancyBootstrapper(), hostConfigs);

【讨论】:

  • 这是否要求 Nancy 服务帐户具有本地管理员权限?
  • 我得到了 tat 代码:System.InvalidOperationException: Unable to configure namespace reservation at Nancy.Hosting.Self.NancyHost.StartListener() at Nancy.Hosting.Self.NancyHost.Start()
  • 好的,知道了。这是因为在法语中“Everyone”是带有两个空格的“Tout le monde”,并且 Nancy 启动的命令不保护带引号的参数......所以该方法目前不可靠,必须在安装程序中使用 netsh .
  • 正是我需要的。谢谢!
  • 如果我尝试对 Uri() 使用任何通配符,Nancy 会抛出异常。如果这有什么不同,我正在使用 Nancy.Hosting.Self.NancyHost()?其他人也一样吗?
【解决方案2】:

AutomaticUrlReservationCreationFailureException 中的Message 会告诉你这一点

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

建议的预留基于您在创建主机时传递给主机的基本 URI。

【讨论】:

  • 啊,是的,看到我应该更仔细地查看错误消息 - 抱歉没有发现。我对网络配置工具很陌生,所以不明白该消息的含义。非常感谢您帮助回答我的问题。
  • 如果我使用 HttpListener 创建自己的 Web 服务器,这一步似乎没有必要——只是好奇为什么 Nancy 需要这样做?
【解决方案3】:

如果您从 Visual Studio 运行 NancyFX,AutomaticUrlReservationCreationFailureException 也会出现。

因此,请确保您以管理员身份运行,以便 NancyFX 设置底层配置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 2019-04-24
    • 2020-04-19
    • 2021-02-07
    • 1970-01-01
    • 2023-03-17
    • 2012-05-29
    相关资源
    最近更新 更多