这是我的代码:
static void Main(string[] args)
{
string url = "http://localhost:3000";
HostConfiguration hostConfigs = new HostConfiguration()
{
RewriteLocalhost = true,
UrlReservations = new UrlReservations() { CreateAutomatically = true }
};
NancyHost nancyHost = new NancyHost(new Uri(url), new DefaultNancyBootstrapper(), hostConfigs);
nancyHost.Start();
Console.WriteLine("Web server running: " + url);
Console.ReadLine();
try
{
nancyHost.Stop();
} catch(Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Web server stopped: " + url);
Console.ReadLine();
}
运行程序后,它会自动执行http://+:3000/
命令,要求在Reserved URL
中添加netsh http add urlacl url=http://+:3000/ user=everyone
的管理权限。
但是,在接受管理权限后,尽管它在http://+:3000/
中添加了Reserved URL
,但是我无法从与路由器连接到同一网络的移动/另一台计算机访问Web服务器。 / p>
在失败太多之后,我还手动添加了这些Reserved URL
:
netsh http add urlacl url=http://localhost:3000/ user=everyone
netsh http add urlacl url=http://127.0.0.1:3000/ user=everyone
netsh http add urlacl url=http://192.168.0.161:3000/ user=everyone
192.168.0.161 -->
我的主机IP地址
但是,它没有用。
答案 0 :(得分:0)
对我来说这是一个愚蠢的错误。
我刚刚关闭了公共防火墙,它可以正常工作!