我有这个奇怪的问题,我确实将ACL保存到ACL列表(以编程方式如此)但是当执行程序时,我仍然收到错误消息“Access Denied”。
public void initRest() {
// Add ACL Service Exception
addACLServiceException();
/*
* initRest will lunch a separate thread that will be responsible for REST service
*/
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
RestServicesImpl services = new RestServicesImpl();
WebHttpBinding binding = new WebHttpBinding();
WebHttpBehavior behavior = new WebHttpBehavior();
WebServiceHost _serviceHost = new WebServiceHost(services, new Uri("http://localhost:8000/RestService"));
_serviceHost.AddServiceEndpoint(typeof(RestServices), binding, "");
_serviceHost.Open();
Console.ReadKey();
_serviceHost.Close();
}).Start();
}
private void addACLServiceException() {
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/K netsh http add urlacl url = http://+:8000/RestService/ user=%USERNAME%";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
}
从CMD窗口运行netsh http show urlacl
(作为管理员)我可以看到保留的URL确实在它应该的位置
Reserved URL : http://+:8000/RestService/
User: DESKTOP-F8O3V2Q\Boss
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;S-1-5-21-990234104-2306344669-2817477651-1001)
答案 0 :(得分:0)
嘿......所以看起来线程执行得更快,然后添加了ACL异常。一个简单的线程睡眠命令就像这样解决了它
public void initRest() {
// Add ACL Service Exception
addACLServiceException();
Thread.Sleep(2000);
... rest of code