The project needs to provide a simple httpserver service with HttpListener. But execution is a hint:
UnhandledException Message: Refusal to interview
In System.Net.HttpListener.AddAll ()
In System.Net.HttpListener.Start ()
Looked up on the internet, as if the problem of UAC permissions, the Internet found the following ways to solve:
For the program to join the administrator rights to execute the manifest configuration file, still cannot resolve, manual Setup program with administrator rights to execute
Ways to solve the problem:
Execute cmd with administrator privileges
Input: netsh http add urlacl url=http://+:9527/icon user=domain\user
Note: DOMAIN is the computer name
Like my user=cmdszh_comperny\cmdszh.
Write the above actions as C # code such as the following (the main program must configure UAC permissions in manifest)
public static void AddAddress (string address)
{
Try
{
AddAddress (Address, environment.userdomainname, environment.username);
}catch (Exception ex) {}
}
public static void AddAddress (string address, string domain, string user)
{
String argsdll = String.Format (@ "http delete urlacl url={0}", address);
string args = string. Format (@ "http add urlacl url={0} user={1}\{2}", address, domain, user);
ProcessStartInfo psi = new ProcessStartInfo ("netsh", argsdll);
Psi. Verb = "RunAs";
Psi. CreateNoWindow = true;
Psi. WindowStyle = Processwindowstyle.hidden;
Psi. UseShellExecute = false;
Process.Start (PSI). WaitForExit ();//Delete Urlacl
PSI = new ProcessStartInfo ("netsh", args);
Psi. Verb = "RunAs";
Psi. CreateNoWindow = true;
Psi. WindowStyle = Processwindowstyle.hidden;
Psi. UseShellExecute = false;
Process.Start (PSI). WaitForExit ();//Join URLACL
}
Original address: http://www.cnblogs.com/cmdszh/archive/2012/08/16/httplistener.html
Problem with HttpListener 503 error in Win7