我正在尝试将 NancyFx 与 SignalR 结合使用。为了托管两者,我使用 Microsoft Owin。但不幸的是,当我尝试通过 PostMen(适用于 chromium 浏览器的 REST-Api 客户端扩展)访问 REST-API 时,我总是收到 503(服务不可用)。因此,我将主要成分提取到一个更简单的程序中,该程序允许我在 Nancy Selfhost 和 Owin 之间切换。 使用 Nancy SelfHost 时,一切正常,但使用 Owin 时仍然出现 503 错误。
internal class Program {
private const bool _USE_SELF_HOST = false;
private static void Main(string[] args) {
if (_USE_SELF_HOST) {
var host = "http://localhost:7084";
UseSelfHost(host);
} else {
var host = "http://localhost:7084";
UsingWebApp(host);
}
}
private static void UseSelfHost(string host) {
var webhost = new NancyHost(new Uri(host));
webhost.Start();
Console.ReadLine();
webhost.Stop();
}
private static void UsingWebApp(string host) {
var nancyHost = WebApp.Start<Startup>(host);
Console.WriteLine($"Nancy started at {host}");
Console.ReadLine();
nancyHost.Dispose();
}
}
public class MainModule : NancyModule {
public MainModule() {
Get["/"] = x => "Hello world!";
}
}
我检查过:
- netsh http show urlacl - 我可以打开此端口
- Visual Studio 正在以管理员权限运行,但不需要这样做。
最佳答案
我的一位同事在我的 netsh 配置中发现了一个错误。我对同一个 tcp 端口有两个 urlacls:
Reservierte URL : http://wks-user:7084/
Benutzer: DOMAIN\user
Abh▒ren: Yes
Delegieren: No
SDDL: D:(A;;GX;;;XXX)
Reservierte URL : http://+:7084/
Benutzer: DOMAIN\user
Abh▒ren: Yes
Delegieren: No
SDDL: D:(A;;GX;;;XXX)
通过删除第一个条目后
netsh http delete urlacl http://wks-user:7084/
一切都按预期进行。
关于owin - 503 将 NancyFx 与 Owin 一起使用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42970507/