Alternative to HttpListener?

有些话、适合烂在心里 提交于 2019-11-29 03:39:29

One 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.

Chris Kimpton

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.

Like the comment by Will Dean on your post says, you could run the following netsh command:

netsh http add urlacl url=http://+:8346/ user="NTAuthority\Authenticated Users" sddl="D:(A;;GX;;;AU)"

Substitute the 'http://+:8346/' with your value, and this will allow any authenticated user to run the webserver at the target endpoint.

huntharo

Regarding the statement:

I've recently discovered that HttpListener needs to be run as Administrator

That's not entirely true and some of the other answers touch on one of the reasons, but there is another:

  1. Noted by other posters: You can grant permissions to a non-Administrator. Fine, but not great.
  2. You can listen on localhost, even on port 80, without being an admin. Note: I recall that only "localhost" works and not "127.0.0.1"... so be sure that you pass localhost to your Prefixes.Add call.

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.

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.

Nowin is a great lib that can be integrated in Owin as ServerFactory without dependency on HttpListener. Were able to drop in replace Microsoft.Owin.Host.HttpListener lib without a hitch

For .NET Core applications there exists a new (cross-platform) HTTP server implemention: Kestrel.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!