HttpListenerException"拒绝访问"对于非管理员 [英] HttpListenerException "access denied" for non-admins

查看:2716
本文介绍了HttpListenerException"拒绝访问"对于非管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了使用的HttpListener 监听-obviously HTTP请求C#应用程序!我使用的命名空间前缀使用也注册的netsh 为当前用户(如建议每个人都在SO)。



现在的问题是,尽管使用Netsh我的应用程序仍然会因非管理员用户访问被拒绝的异常。该操作系统是Windows 7



更新:好像我的应用程序没有执行的netsh 命令时,我出现以非管理员用户运行它。是否与我的代码的任何问题? 。没有抛出的异常

  AddAddress(HTTP://本地主机:8400 /,Environment.UserDomainName,Environment.UserName ); 

的HttpListener _listener =新的HttpListener();
_listener.Prefixes.Add(HTTP://本地主机:8400 /);
_listener.Start();

...从SO线被盗

/ **方法。对不起,不记得笔者** /
静态无效AddAddress(字符串的地址,字符串域,字符串用户)
{
字符串ARGS =的String.Format(@HTTP添加urlacl URL = {0},地址)+=用户\+域名+\\+用户+\;

的ProcessStartInfo PSI =新的ProcessStartInfo(netsh的参数);
psi.Verb =运行方式;
psi.CreateNoWindow = TRUE;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = TRUE;

的Process.Start(PSI).WaitForExit();
}


解决方案

这是我使用时,行我做的是的HttpListener:

 的netsh的http添加urlacl URL = HTTP:// +:8008 / USER =每个人听=是

用户可以是单个用户或用户组。所以如果你想只有管理员才能够访问,例如:

 的netsh的http添加urlacl URL = HTTP:// +:8008 /用户=管理员听= YES 

您可以获取有关命令的帮助:

 的netsh的http添加urlacl帮助

注意, URL = 是可选的。此外,旧版本的命令都要求真或假的听参数。当前版本使用yes或no。


I have written a C# application that uses HttpListener to listen for HTTP requests -obviously! The namespace prefix I use is also registered using netsh for the current user (as suggested by everyone on SO).

The problem is despite using netsh my application still throws an "access is denied" exception for non-admin users. The OS is Windows 7.

Update: It appears as though my application is not executing the netsh command when I run it with a non-admin user. Is there any problems with my code? There are no exceptions thrown.

    AddAddress("http://localhost:8400/", Environment.UserDomainName, Environment.UserName);

    HttpListener _listener = new HttpListener();
    _listener.Prefixes.Add("http://localhost:8400/");
    _listener.Start();

    ...

    /** method stolen from an SO thread. sorry can't remember the author **/
    static void AddAddress(string address, string domain, string user)
    {
        string args = string.Format(@"http add urlacl url={0}", address) + " user=\"" + domain + "\\" + user + "\"";

        ProcessStartInfo psi = new ProcessStartInfo("netsh", args);
        psi.Verb = "runas";
        psi.CreateNoWindow = true;
        psi.WindowStyle = ProcessWindowStyle.Hidden;
        psi.UseShellExecute = true;

        Process.Start(psi).WaitForExit();
    }

解决方案

The line that I use when I'm doing an HttpListener is:

netsh http add urlacl url=http://+:8008/ user=Everyone listen=yes

The user can be an individual user or a user group. So if you want only Administrators to have access, for example:

netsh http add urlacl url=http://+:8008/ user=Administrators listen=yes

You can get help on the command:

netsh http add urlacl help

Note that the url= is optional. Also, older versions of the command require true or false for the listen parameter. Current versions use yes or no.

这篇关于HttpListenerException"拒绝访问"对于非管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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