HttpListener .NET Prefix Error with anything other than localhost

I am trying to use C # and HttpListener with a prefix for something other than localhost, and it fails (i.e. if I give it server1 , i.e.

http://localhost:1234 works, but

http://server1:1234 does not work

The code...

 HttpListener listener = new HttpListener(); String prefix = @"http://server1:1234"; listener.Prefixes.Add(prefix); listener.Start(); 

Failure occurs on listener.Start() , with the exception of Access is denied. .

+7
source share
2 answers

I had the same problem and solved it by adding URL reservation for the specified URL namespace for the user / users in Network Shell (netsh). Here's an example of how to reserve a URL for each user, run it on the command line as an administrator:

 netsh http add urlacl url=http://server1:1234/ user=Everyone 

Here is an example of how to reserve a URL for a single user, run it on the command line as an administrator:

 netsh http add urlacl url=http://server1:1234/ user=Steve 

This way you do not need to run the application as an administrator

+8
source

Does your application run with elevated privileges?

Regular accounts cannot connect the Http pipeline without prior reservation.

http://msdn.microsoft.com/en-us/library/Aa364673

This can be done programmatically during installation. Let me know if this is interesting and I will dig out the code.

EDIT:

In fact, since I cannot determine where the code came from at the moment, I cannot publish it here. There's a codeplex project for this kind of thing , which is definitely worth a break.

/ EDIT

Here you can make a reservation at the command line:

http://www.casadehambone.com/HowToAddAURLACLAndAvoidAddressAccessDeniedExceptionInWindowsVista.aspx

+3
source

All Articles