简体   繁体   中英

Serve canned offline web content using the Web Browser control

I'm developing a C# replacement for a legacy VB app for my company. 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. 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.

My questions are about how to store and deliver the web content.

  • 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?
  • 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. Is it?
  • The legacy VB implementation alters the web files to inject data using Substring methods; 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.
  • 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.
  • 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. 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.

Another option I have successfully used as a lightweight embedded web server is logv-http , it has a pretty easy to configure syntax. 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. If there are lots of replaces wrapping them into a RegEx should help performance.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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