I'm developing an application that is so far using HttpListener to provide a small standalone http server. However, I've recently discovered that HttpListener needs to be run as Administrator, which is not always going to be possible.
What would the best alternative be? I need http GET and POST, both of which are not simply reading/writing files on the filesystem, they need to run custom .Net code.
My research so far has brought up Cassini, but as far as I can tell, I would have to write a custom version. Is there anything else? In partiular something with the same interface as HttpListener, but that does not require Administrator privileges would be amazing!
Nowin is a great lib that can be integrated in
Owin
asServerFactory
without dependency onHttpListener
. Were able to drop in replaceMicrosoft.Owin.Host.HttpListener
lib without a hitchOne alternative that I've found is C# Webserver on CodePlex.
"... a flexible http server which can be embedded in any .Net application. It has a modular design where features are added using modules. The server also supports REST and all http verbs ..."
It has an HttpListener class which I imagine is similar to System.Net.HttpListener, but I haven't used either one of them yet so I can't be certain.
One solution to this is covered by this other question - you can give yourself permissions to run HttpListener as a non-admin.
You could get the app to be started from a command file that sorts out the permissions and then runs the real app.
Ok, so you have a regular desktop app that needs to allow inbound http connections - hmm - won't windows firewall be an issue?
Assuming not, it sounds almost like a webservice - could you go that route - expose the URLs via that? Although my .Net knowledge is not deep enough to know if you still need to run a specific http server to answer requests. Spring.Net is probably worth a look.
Regarding the statement:
That's not entirely true and some of the other answers touch on one of the reasons, but there is another:
We're shipping an internal tool that allows developers to run an HTTP-based app host on their PCs and we at first thought using HttpListener would not be possible due to the Admin (or Admin-granted permissions) problem, but then we found that localhost works just fine without being an Admin. It sort of makes sense: listening externally is "dangerous" but listening on the local machine is not quite as dangerous.
Like the comment by Will Dean on your post says, you could run the following netsh command:
Substitute the 'http://+:8346/' with your value, and this will allow any authenticated user to run the webserver at the target endpoint.