Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

.net - HttpListener.Start() AccessDenied error on Vista

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...