.NET的HttpListener前缀的问题与localhost以外的任何 [英] .NET HttpListener Prefix issue with anything other than localhost
问题描述
我想用C#和的HttpListener
与localhost以外的任何前缀和失败(即,如果我给它 server1的
,即
I'm trying to use C# and HttpListener
with a prefix of anything other than localhost and it fails (i.e. if I give it server1
, i.e.
的http://本地主机:1234
的作品,但
的http://服务器1:1234
失败
中的代码...
HttpListener listener = new HttpListener();
String prefix = @"http://server1:1234";
listener.Prefixes.Add(prefix);
listener.Start();
在 listener.Start()
时发生该故障与访问异常被拒绝。
。
推荐答案
我有同样的问题曾经和我通过添加URL保留指定的URL命名空间为用户/用户解决了它。网络外壳(Netsh的),下面是关于如何RESERV一个网址为每一位用户,在命令提示符以管理员身份运行此例子:
I had the same issue once and i solved it by adding an URL reservation for the specified URL namespace for a user/users to the Network Shell (netsh). Here's an example on how to reserv an URL for every user, run this in the command prompt as an administrator:
netsh http add urlacl url=http://server1:1234/ user=Everyone
下面是关于如何RESERV的URL为一个用户,在命令提示符以管理员身份运行此例子:
Here's an example on how reserv an URL for one user, run this in the command prompt as an administrator:
netsh http add urlacl url=http://server1:1234/ user=Steve
在这种方式,你不需要运行应用程序作为管理员
In this way you don't need to run the application as an administrator
这篇关于.NET的HttpListener前缀的问题与localhost以外的任何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!