OWIN 无法以 "The network location cannot be reached" 开头

OWIN fails to start with "The network location cannot be reached"

我正在尝试 运行 .NET 4.5 控制台应用程序上的以下代码:

var app = WebApp.Start<Startup>("http://127.0.0.1:9000/");

这适用于我同事的机器,但不适用于我的机器。

异常消息为“Exception has been thrown by the target of an invocation.”,内部异常为“The network location cannot be reached. For information about network troubleshooting, see Windows Help”。

我已经尝试关闭我的防火墙,重置我的主机文件,没有杀毒软件 运行ning,刷新我的 DNS 和 cleaned/rebuilt 我的解决方案。

这是堆栈跟踪:

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(StartContext context)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
   at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start[TStartup](String url)
   at OwinTest.Program.Main(String[] args) in C:\Temp\OwinTest\OwinTest\Program.cs:line 12

如果我将代码更改为这样它就可以工作:

var app = WebApp.Start<Startup>("http://localhost:9000/");

但是上面的代码不是我要找的。

如有任何想法,我们将不胜感激。

试试这个:

var app = WebApp.Start<Startup>("http://0.0.0.0:9000/");

0.0.0.0 应该意味着它正在侦听所有 IP...

经过一整天的研究和故障排除,以下命令起作用了:

netsh http add iplisten 127.0.0.1

当我在命令提示符下 运行 时,我没有收到任何错误。