The problem of 503 error in Win7 with HttpListener

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.