first_page

Client-Side ASP.NET Revisited?

The WebBrowser control runs with the same security paranoia model that’s in Internet Explorer. This means is that a Web page referencing local external JavaScript or CSS files will not be rendered—even when an absolute, HTTP URI pointed at a client-side ASP.NET ‘server’ is used (such as the one described by Dino Esposito in “ASP. NET Client-side Hosting with Cassini”). Evidently the WebBrowser control will not load a file declared in a src or href attribute from a location that is in any way related to the local file system.

My workaround is to ‘inject’ the contents of these files into the Web page during the load event of the Windows Forms hosting the WebBrowser control:

#region Load external files:

this._clientXml = new XPathDocument(Properties.Settings.Default.ClientXml);

this._clientXslt.Load(Properties.Settings.Default.ClientXslt);

string css = String.Empty;
using (StreamReader file = File.OpenText(Properties.Settings.Default.ClientCss))
   css = file.ReadToEnd();

string jsData = String.Empty;
using (StreamReader file = File.OpenText(Properties.Settings.Default.DataValidationJs))
   jsData = file.ReadToEnd();

string js = String.Empty;
using (StreamReader file = File.OpenText(Properties.Settings.Default.ClientJs))
   js = file.ReadToEnd();

using (StreamReader file = File.OpenText(Properties.Settings.Default.ClientXhtml))
   string xhtml = file.ReadToEnd();
xhtml = String.Format(xhtml,jsData,js,css);
this._browser.Document.Write(xhtml);

#endregion

Before I resorted to such a primitive (and effective) solution, other options related to Client-Side ASP.NET ‘servers’ were examined. The following table summarizes:

“[ASP. NET Client-side Hosting with Cassini](http://msdn.microsoft.com/msdnmag/issues/03/01/CuttingEdge/)” Not very popular at Microsoft since January 2003. Evidently ASMX or WSE is preferred—two acronyms I can’t delve into right now.
“[Explore and Extend the Cassini Web Server](http://www.devx.com/dotnet/Article/11711)” Another 2003 exposé of the technology that eventually ended up in Visual Studio 2005.
“[Client-side Environment for ASP Pages](http://msdn.microsoft.com/msdnmag/issues/1000/cutting/)” An ancient article from 2000 by Dino Esposito—just to show how far back he goes with this brilliant stuff. We’re talking pre-.NET stuff here.
“[Executing ASPX pages without a web server](http://radio.weblogs.com/0105476/stories/2002/07/12/executingAspxPagesWithoutAWebServer.html)” Jim Klopfenstein’s code sample appears superior to the tame examples Dino has his ASP.NET article (above).
[System.Web.Hosting Namespace](http://msdn2.microsoft.com/en-us/library/84006ws2.aspx) This is the namespace that contains the classes that make Jim Klopfenstein’s code run. This namespace is also [in .NET 1.x](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhosting.asp).

rasx()