HttpListener.Start() AccessDenied error on Vista

前端 未结 2 906
盖世英雄少女心
盖世英雄少女心 2020-12-15 08:33

Running this code as a regular user throws HttpListenerException (access denied). Snippet runs ok as an administator

class Program
{
    static void Main(st         


        
相关标签:
2条回答
  • 2020-12-15 09:10

    Is that URI already registered on the system?

    http://msdn.microsoft.com/en-us/library/system.net.httplistenerexception.aspx says that would be one cause.

    0 讨论(0)
  • 2020-12-15 09:25

    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.

    0 讨论(0)
提交回复
热议问题