运行此code作为普通用户抛出HttpListenerException(拒绝访问)。片段作为administator运行正常
类节目
{
静态无效的主要(字串[] args)
{
的HttpListener监听器=新的HttpListener();
。监听器prefixes.Add(HTTP:// MYIP:8080 /程序/);
listener.Start();
//.... 等等
}
}
我继续使用Netsh(netsh的HTTP显示列出了URI)添加的URI
的netsh的http添加urlacl URL = HTTP:// +:8080 /应用程序的用户=域\用户
仍然得到同样的错误。添加的ACL做其他项目的工作(他们没有使用的HttpListener虽然)。我试着多端口/应用程序名称的组合,没有任何工程。
任何想法可能是什么原因?
运行.NET 3.5 SP1对Vista 解决方案
我不明白为什么,但在这里它是。看来,原因是我的网卡配置有2个IP地址。
如果在codeI指定IPS的一个(像我一样在上面的问题)
监听器prefixes.Add(HTTP:// myip1:8080 /程序/)。
随后,以避免例外,我需要与注册它的IP绑定弱通配符
的netsh的http添加urlacl URL = HTTP:// myip1:8080 /应用程序的用户=域\用户
不过,如果我添加preFIX的大力通配符(加号)
监听器prefixes.Add(HTTP:// +:8080 /程序/)。
和使用相同的外卡登记
的netsh的http添加urlacl URL = HTTP:// +:8080 /应用程序的用户=域\用户
那么有没有错误,我可以从两个IP访问我的应用程序。
Running this code as a regular user throws HttpListenerException (access denied). Snippet runs ok as an administator
class Program
{
static void Main(string[] args)
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://myip:8080/app/");
listener.Start();
//.... and so on
}
}
i went ahead and added the uri using netsh (netsh http show lists the uri)
netsh http add urlacl url=http://+:8080/app user=domain\user
still getting the same error. Adding ACLs did work for other projects (they didn't use HttpListener though). I tried multiple port/application name combinations, nothing works.
Any ideas what might be the cause?
Running .Net 3.5 SP1 on Vista
解决方案I do not understand why but here it is. It seems that the cause is that my network card is configured with 2 IPs.
if in the code i specify one of the ips (like i did in question above)
listener.Prefixes.Add("http://myip1:8080/app/");
then to avoid exception i need to register it with IP-bound weak wildcard
netsh http add urlacl url=http://myip1:8080/app user=domain\user
however if i add prefix with the strong wildcard (plus sign)
listener.Prefixes.Add("http://+:8080/app/");
and register with the same wild card
netsh http add urlacl url=http://+:8080/app user=domain\user
then there is no error and i can access my app from both ip.