The problem of 503 error in Win7 with HttpListener

Source: Internet
Author: User

The project requires HttpListener to provide a simple httpserver service, but the operation is prompt:

UnhandledException Message: Access Denied

In System.Net.HttpListener.AddAll ()

In System.Net.HttpListener.Start ()

Online check, as if the problem of UAC permissions, the Internet found the following solution:

The manifest profile that the program has added administrator privileges to run is still not resolved, and the manual Setup program runs with administrator privileges and can be

Ways to solve the problem:

Run 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 action as C # code as follows (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 ();//Add Urlacl
}


Original address: http://www.cnblogs.com/cmdszh/archive/2012/08/16/httplistener.html


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.