C# Windows Service中使用Signalr开启服务时候报System.Net.HttpListenerException:拒绝访问解决方法

Question:WIN7或WIN10下面,使用Windows Service作为SignalR的宿主时候,执行WebApp.Start("http://192.168.1.11:8081/"); 报System.Net.HttpListenerException:拒绝访问的错误


解决方法:

1、以管理员权限打开CMD命令行

2、输入 netsh http show urlacl查看http://192.168.1.11:8081/在不在里面

3、先删除可能存在的错误urlacl,这里的*号代指localhost、127.0.0.1、192.168.199.X本地地址和+号等。

命令:netsh http delete urlacl url=http://*:8081/

这边使用: netsh http delete urlacl url=http://192.168.1.11:8081/

4、将上面删除的地址重新加进url,user选择所有人

命令:netsh http add urlacl url=http://*:8080/  user=Everyone
这边使用:netsh http add urlacl url=http://192.168.1.11:8081/  user=Everyone
5、配置防火墙

可以用下面命令来配置

netsh advfirewall firewall Add rule name=\"命令行Web访问8081\" dir=in protocol=tcp localport=8081 action=allow

或者通过防火墙界面的 入站规则 里面添加一个8081的TCP端口

C# Windows Service中使用Signalr开启服务时候报System.Net.HttpListenerException:拒绝访问解决方法