简体   繁体   English

使用Web浏览器控件提供离线罐装Web内容

[英]Serve canned offline web content using the Web Browser control

I'm developing a C# replacement for a legacy VB app for my company. 我正在为公司的旧版VB应用程序开发C#替代品。 The front end is basically a Web Browser control inside of a Windows form, serving offline content which is sometimes altered to include the user's data. 前端基本上是Windows窗体内部的Web浏览器控件,用于提供脱机内容,有时会对其进行更改以包括用户数据。 Because there are 100 or more web files in the legacy app, we are going to reuse the web UI from the old application with a new C# wrapper around it, modifying them as needed. 由于旧版应用程序中有100个或更多的Web文件,因此我们将在旧应用程序中使用新的C#包装器重用旧应用程序的Web UI,并根据需要对其进行修改。

My questions are about how to store and deliver the web content. 我的问题是关于如何存储和交付Web内容的。

  • Does it make sense to copy the web files to a temporary folder and point the Web Browser control to the file:// address of the temporary folder? 将Web文件复制到临时文件夹并将Web浏览器控件指向临时文件夹的file://地址是否有意义?
  • Is there some kind of pre-built offline-friendly server framework that makes more sense than copying the files to a temporary folder? 是否有某种预先构建的对离线友好的服务器框架,比将文件复制到临时文件夹更有意义?
  • I have the web source files in my project as resources, but I'm not sure if that is appropriate for my uses. 我的项目中有Web源文件作为资源,但是我不确定这是否适合我的用途。 Is it? 是吗?
  • The legacy VB implementation alters the web files to inject data using Substring methods; 传统的VB实现更改Web文件以使用Substring方法注入数据; it searches for magic strings and replaces them with the appropriate data. 它搜索魔术字符串,并将其替换为适当的数据。 That code smells pretty bad, is there a better, more native data injection strategy I should look at? 该代码闻起来很糟糕,我是否应该考虑一种更好的,更本地化的数据注入策略?

Some background: 一些背景:

  • The data is presented using HTML\\CSS\\JS and also sometimes XSL. 数据使用HTML \\ CSS \\ JS(有时也使用XSL)显示。
  • The browser delivers content that is available at compile time. 浏览器提供在编译时可用的内容。
  • I'm going to have to handle some events using c# code when users click on buttons of the page. 当用户单击页面的按钮时,我将不得不使用c#代码处理一些事件。
  • I'm free to choose whatever approach is necessary to implement the application. 我可以自由选择实现该应用程序所需的任何方法。

Hosting 主机

I would probably avoid using a temporary location for the web content it just seems a little crude. 我可能会避免使用一个临时位置作为Web内容,这似乎有些粗糙。 If there is no internal linking between your html pages and all the css/js is embedded in one file it may be easier to just use the WebBrowser.DocumentText property. 如果您的html页面之间没有内部链接,并且所有css / js都嵌入到一个文件中,则仅使用WebBrowser.DocumentText属性可能会更容易。

Another option I have successfully used as a lightweight embedded web server is logv-http , it has a pretty easy to configure syntax. 我已经成功用作轻量级嵌入式Web服务器的另一个选项是logv-http ,它具有易于配置的语法。 If you want to configure against anything other than localhost it does require administrator privileges but it sounds like everything will be local. 如果要针对本地主机以外的其他任何配置进行配置,则它确实需要管理员权限,但听起来一切都将是本地的。

var server = new Server("localhost", 13337);
server.Get("http://localhost:13337" ,(req, res) => res.Write("Hello World!"));
server.Start();

Templating 模板

I think the string replaces aren't necessarily bad depends how many there are and how complicated they are trying to be, but for simple find replace it shouldn't be too hard to manage. 我认为字符串替换不一定坏,取决于有多少个字符串以及它们要变得多么复杂,但是对于简单的find替换来说,它应该不太难管理。 If there are lots of replaces wrapping them into a RegEx should help performance. 如果有很多替换项,将它们包装到RegEx中将有助于提高性能。

Storing the web content as embedded resources is probably how I would go that way you can read them out at run-time do you pre-processing and then return either via the the web server method or direct into the DocumentText. 将Web内容存储为嵌入式资源可能是我的处理方式,您可以在运行时将它们读出来,然后进行预处理,然后通过Web服务器方法返回或直接返回到DocumentText中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM