HttpListener 的替代品?

发布于 2024-07-08 12:50:13 字数 294 浏览 7 评论 0原文

我正在开发一个应用程序,到目前为止,它使用 HttpListener 来提供一个小型独立的 http 服务器。 但是,我最近发现 HttpListener 需要以管理员身份运行,但这并不总是可行。

最好的选择是什么? 我需要 http GET 和 POST,它们都不仅仅是在文件系统上读取/写入文件,它们需要运行自定义 .Net 代码。

到目前为止,我的研究已经提出了卡西尼号,但据我所知,我必须编写一个自定义版本。 还有别的事吗? 特别是与 HttpListener 具有相同接口但不需要管理员权限的东西将是惊人的!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

书间行客 2024-07-15 12:50:14

就像 Will Dean 对您的帖子的评论所说,您可以运行以下 netsh 命令:

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

用您的值替换“http://+:8346/”,这将允许任何经过身份验证的用户在目标端点运行 Web 服务器。

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.

吾家有女初长成 2024-07-15 12:50:14

关于声明:

我最近发现 HttpListener 需要以管理员身份运行

这并不完全正确,其他一些答案涉及其中一个原因,但还有另一个原因:

  1. 其他发帖者指出:您可以向非管理员授予权限。 不错,但不是很好。
  2. 您可以在本地主机上监听,甚至可以在端口 80 上监听,而无需成为管理员。 注意:我记得只有“localhost”有效,而“127.0.0.1”无效...所以请确保将 localhost 传递给 Prefixes.Add 调用。

我们正在发布一个内部工具,允许开发人员在他们的 PC 上运行基于 HTTP 的应用程序主机,我们起初认为由于管理员(或管理员授予的权限)问题而无法使用 HttpListener,但后来我们发现本地主机无需管理员即可正常工作。 这是有道理的:从外部监听是“危险的”,但在本地机器上监听并不那么危险。

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.

但可醉心 2024-07-15 12:50:14

对于 .NET Core 应用程序,存在一个新的(跨平台)HTTP 服务器实现:Kestrel

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

捂风挽笑 2024-07-15 12:50:14

好的,那么您有一个需要允许入站 http 连接的常规桌面应用程序 - 嗯 - Windows 防火墙不会成为问题吗?

假设不是,它听起来几乎就像一个网络服务 - 你能走那条路 - 通过它公开 URL 吗? 虽然我的.Net知识还不够深,不知道是否还需要运行特定的http服务器来应答请求。 Spring.Net 可能值得一看。

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.

灯角 2024-07-15 12:50:14

Nowin 是一个很棒的库,可以集成到 Owin 中作为 ServerFactory 而不依赖于 HttpListener。 我们能够顺利地替换 Microsoft.Owin.Host.HttpListener lib

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

风柔一江水 2024-07-15 12:50:14

截至 2023 年,现在有一个新的替代方案: SpaceWizzards.HttpListener.HttpListener 是 1 :1 替换现有的 System.Net.HttpListener。 nuget 可用作 SpaceWizards.HttpListener。 尽管其版本号较低,为 0.1.0,但在撰写本文时,其下载量已超过 40 万次。 第一次测试表明它确实按预期工作。

As of 2023, there's now a new alternative: SpaceWizzards.HttpListener.HttpListener is a 1:1 replacement of the existing System.Net.HttpListener. The nuget is available as SpaceWizards.HttpListener. Despite its low version number of 0.1.0 it already has over 400k downloads at the time of this writing. A first test shows that it's actually working as expected.

鹊巢 2024-07-15 12:50:13

我发现的一种替代方案是 CodePlex 上的 C# Webserver

“...一个灵活的 http 服务器,可以嵌入到任何 .Net 应用程序中。它采用模块化设计,使用模块添加功能。该服务器还支持 REST 和所有 http 动词 ...”

它有一个 HttpListener 类,我认为它与 System.Net.HttpListener 类似,但我还没有使用过其中任何一个,所以我不能确定。

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.

一袭水袖舞倾城 2024-07-15 12:50:13

这个其他问题 - 您可以授予自己以非管理员身份运行 HttpListener 的权限。

您可以从命令文件启动应用程序,该命令文件整理权限,然后运行真正的应用程序。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文