Vista 上的 HttpListener.Start() AccessDenied 错误 [英] HttpListener.Start() AccessDenied error on Vista

查看:27
本文介绍了Vista 上的 HttpListener.Start() AccessDenied 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以普通用户身份运行此代码会引发 HttpListenerException(访问被拒绝).Snippet 作为管理员运行正常

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
     }
}

我继续使用 netsh 添加了 uri(netsh http show 列出了 uri)

i went ahead and added the uri using netsh (netsh http show lists the uri)

netsh http add urlacl url=http://+:8080/app user=domainuser

仍然出现相同的错误.添加 ACL 确实适用于其他项目(尽管他们没有使用 HttpListener).我尝试了多个端口/应用程序名称组合,但没有任何效果.

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?

在 Vista 上运行 .Net 3.5 SP1

Running .Net 3.5 SP1 on Vista

推荐答案

我不明白这是为什么.看来是我的网卡配置了2个IP的原因.

I do not understand why but here it is. It seems that the cause is that my network card is configured with 2 IPs.

如果在代码中我指定了一个 ips(就像我在上面的问题中所做的那样)

if in the code i specify one of the ips (like i did in question above)

listener.Prefixes.Add("http://myip1:8080/app/");

然后为了避免异常,我需要使用绑定 IP 的弱通配符来注册它

then to avoid exception i need to register it with IP-bound weak wildcard

netsh http add urlacl url=http://myip1:8080/app user=domainuser

但是,如果我添加带有强通配符(加号)的前缀

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=domainuser

然后没有错误,我可以从两个 IP 访问我的应用程序.

then there is no error and i can access my app from both ip.

这篇关于Vista 上的 HttpListener.Start() AccessDenied 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆