C# 将轻量级 Web 服务器嵌入到 .net 应用程序 (node.js) 中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11746298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embedding a lightweight web server into a .net application (node.js)?
提问by S16
I have a project built with Awesomium built in .NET and it requires the use of Flash. Flash throws security errors trying to access local content (video player) and the solution(s) Awesomium offers have not been ported to the .NET wrapper yet. I'm wondering if there is a fairly straight-forward way to include a run-time web server in the application where I can just pick some arbitrary port and create a localhost server when the application runs and point my Awesomium browser there.
我有一个用 .NET 内置的 Awesomium 构建的项目,它需要使用 Flash。Flash 会在尝试访问本地内容(视频播放器)时引发安全错误,并且 Awesomium 提供的解决方案尚未移植到 .NET 包装器。我想知道是否有一种相当直接的方法可以在应用程序中包含一个运行时 Web 服务器,我可以在其中选择一些任意端口并在应用程序运行时创建一个 localhost 服务器并将我的 Awesomium 浏览器指向那里。
Any ideas?
有任何想法吗?
采纳答案by lnmx
NHttpprovides an HTTP server with request parsing, but you have to roll your own responses. There's also Kayak, and the framework's own HttpListener.
NHttp提供了一个带有请求解析的 HTTP 服务器,但你必须滚动你自己的响应。还有Kayak和框架自己的HttpListener。
Nancyis a full MVC framework, supports the ASP.NET Razor syntax, and has lots of options for configuration and extensibility. There's a self-host packageavailable on nuget.
Nancy是一个完整的 MVC 框架,支持 ASP.NET Razor 语法,并且有很多配置和可扩展性选项。nuget 上有一个自托管包。
If you just need to serve up a SWF file and some JSON data, the first set would probably be simpler to integrate -- if you need to render full web pages, I would recommend Nancy.
如果您只需要提供一个 SWF 文件和一些 JSON 数据,第一组可能更容易集成——如果您需要呈现完整的网页,我会推荐 Nancy。
回答by Timothy Strimple
I appears as though you can play local flash content as long as the content is set to be trusted.
只要内容设置为受信任,我似乎就可以播放本地 Flash 内容。
What is Flash Player security for local content?
Local content can be designated as trusted so that it is not interrupted by this dialog box and is allowed to function as designed. This trust must be explicitly designated in one of two ways.
By running a software installation program in which the content in the application you install is already registered as trusted. When you run an installation program, you are explicitly allowing a program to be installed on your computer. Thus, the publisher of the application can automatically register the content with Flash Player as trusted.
By adding specific content or directories to a list of trusted files, through the Global Security Settings panel in the Flash Player Settings Manager. In this panel, you can designate specific content or even directories as trusted by manually registering locations with Flash Player. For step-by-step instructions on how to designate content as trusted, see the TechNote: How do I let local Flash content communicate with the Internet?
可以将本地内容指定为受信任的,这样它就不会被此对话框中断并按设计运行。这种信任必须以两种方式之一明确指定。
通过运行软件安装程序,其中您安装的应用程序中的内容已注册为受信任。当您运行安装程序时,您明确允许在您的计算机上安装程序。因此,应用程序的发布者可以在 Flash Player 中自动将内容注册为受信任的。
通过 Flash Player 设置管理器中的全局安全设置面板,将特定内容或目录添加到受信任文件列表中。在此面板中,您可以通过使用 Flash Player 手动注册位置来将特定内容甚至目录指定为受信任的。有关如何将内容指定为受信任的分步说明,请参阅技术说明:如何让本地 Flash 内容与 Internet 通信?
回答by Steven Robbins
I'm guessing this is Windows.. You don't (or shouldn't) need to use a web server. If you create a cfg file, doesn't matter what it's called, in this directory:
我猜这是 Windows .. 你不需要(或不应该)使用网络服务器。如果你创建一个 cfg 文件,不管它叫什么,在这个目录中:
%appdata%\Macromedia\Flash Player#Security\FlashPlayerTrust
%appdata%\Macromedia\Flash Player#Security\FlashPlayerTrust
And put a single line in it containing the path to the folder you want to trust then Flash will load local resources without security issues. You can delete the file again when you shutdown (this is what we do).
并在其中添加一行包含您要信任的文件夹的路径,然后 Flash 将加载本地资源而不会出现安全问题。您可以在关机时再次删除该文件(这是我们所做的)。
Same principal on other platforms, just the location of that FlashPlayerTrust folder is different.
其他平台上的原理相同,只是 FlashPlayerTrust 文件夹的位置不同。
回答by Marek
For ASP.Net MVC (and other) self-hosting You can use OWINimplementations:
对于 ASP.Net MVC(和其他)自托管您可以使用OWIN实现:
Open Web Interface for .NET (OWIN) defines an abstraction between .NET web servers and web applications. OWIN decouples the web application from the server, which makes OWIN ideal for self-hosting a web application in your own process, outside of IIS.
Open Web Interface for .NET (OWIN) 定义了 .NET Web 服务器和 Web 应用程序之间的抽象。OWIN 将 Web 应用程序与服务器分离,这使得 OWIN 非常适合在 IIS 之外在您自己的进程中自托管 Web 应用程序。
Hereyou can find a simple example with WebAPI.
在这里您可以找到一个简单的 WebAPI 示例。
回答by Mario
Here's another alternative I wrote last year and and has served me well.
这是我去年写的另一个替代方案,并且对我很有帮助。
EmbedIO: https://github.com/unosquare/embedio
嵌入: https://github.com/unosquare/embedio
I use it mostly to create RESTful services on the Raspberry Pi (soft-float). Updated code for Mono 3.10, support for WebSockets, and Asynchronous handling of requests.
我主要使用它在 Raspberry Pi(软浮动)上创建 RESTful 服务。更新了 Mono 3.10 的代码、对 WebSockets 的支持以及请求的异步处理。
NuGet Package also available.
NuGet 包也可用。
回答by Stefan Steiger
If you need a little ASP.NET on the server side, use Mono.WebServer and Mono.WebServer.XSP.
Here:
https://github.com/mono/xsp/tree/master/src
如果您在服务器端需要一点 ASP.NET,请使用 Mono.WebServer 和 Mono.WebServer.XSP。
这里:https:
//github.com/mono/xsp/tree/master/src
Else, you can use uhttpsharp:
https://github.com/raistlinthewiz/uhttpsharp
否则,您可以使用 uhttpsharp:https:
//github.com/raistlinthewiz/uhttpsharp
Or you can use "webserver" from codeplex:
http://webserver.codeplex.com/
或者您可以使用 codeplex 中的“网络服务器”:http://webserver.codeplex.com/
Or more heavyweight, Cassini:
https://cassinidev.codeplex.com/
或者更重量级的,Cassini:https:
//cassinidev.codeplex.com/
回答by Nicholas DiPiazza
If you would like to take advantage of HTTP2 ability to stream content efficiently, you can also use GRPC to embed an HTTP2 server.
如果您想利用 HTTP2 的能力来高效地流式传输内容,您还可以使用 GRPC 来嵌入 HTTP2 服务器。
See:
看:

