【发布时间】:2019-12-28 14:50:28
【问题描述】:
这是我的代码:
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();
}
运行我的程序后,它通过自动执行netsh http add urlacl url=http://+:3000/ user=everyone这个命令来请求在Reserved URL中添加http://+:3000/的管理权限。
但是,在接受管理权限后,虽然它在Reserved URL 中添加了http://+:3000/,但我无法从我的手机/另一台与我的路由器连接到同一网络的计算机访问我的网络服务器。
失败太多后,我也手动添加了这些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=everyone192.168.0.161 -->我的主机IP地址
但是,它没有用。
【问题讨论】: