views:

213

answers:

2

I'm trying to use C# and HttpListener with a prefix of anything other than localhost and it fails (i.e. if I give it "server1", i.e.

http://localhost:1234 works, but

http://server1:1234 fails

The code is...

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

The failure occurs on listener.Start() with an exception of "Access is denied.".

+1  A: 

Is your app running with elevated privilege?

Normal accounts cannot hook the Http pipeline without first making a reservation.

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

It can be done programatically at install time. Let me know if this is of interest, and I'll dig out some code.

EDIT:

Actually, as I can't identify where the code came from at the moment, I can't post it here. There's a codeplex project for doing this kind of thing which is definitely worth picking apart.

/EDIT

Here's a way make the reservation on the command line:

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

spender
A: 

Many thanks, I'll give this a try. I really appreciate your response!

Update: just tested w/ "Run as Administrator" for Command Prompt (this is a console app) and it worked perfectly. Thank you so much!

Joel