Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

WebBrowser Control – No PostData in Navigating Event


:P
On this page:

So I was going over some demos for my ASP.NET Core talk this week and I was looking over my ASPNET Hosting demos which host the ASP.NET runtime in a WinForms application. There are a number of examples that use a Web Browser embedded into the page.

 

Way back in .NET 1.x I struggled to find and customized a WebBrowser control class using low level COM to hook up basic browser functionality for navigation and basic event access to many common operations without relying on the 3 meg mshtml runtime. The control works, but it's pretty finicky and the design experience is not quite optimal.

 

WinForms . NET 2.0 now includes a new Web Browser control and mshtml is now part of the runtime I believe so you don’t have to worry about shipping this 3 meg monster interop assembly. Sounds great, right?

 

Yeah, yeah, the control is nice for very basic scenarios. It’s easy to drop on a form and it handles many common display only scenarios. However, one of the most frequent tasks that I do is take over the navigation process of the browser and hook up navigation that bypasses the browser’s navigation engine and instead routes request to local files. One of the examples I use in the Hosting application is running an Web Site completely offline without any Web Server directly from disk.

 

So there’s a Navigating event which is meant to be like the WebBrowser’s BeforeNavigate event that can be used to override Navigation with a custom navigation for special Urls or translating URLs into something that the application can work with and generate HTML. Great – it’s way easier than my old code, but the damn simple minded event doesn’t publish the browser’s POST data. Or the headers. Or the flags. Who are these people making decisions on crap like this? They mirror an API that already exist and then nilly willy decide to leave out functionality that already exists on the old API arbitrarily.

 

Right – who would ever need to look at the POST data or Headers in their code? It’s rare, but damn it the old API had it, why not go the extra two steps and add a couple of properties to bring that data back? Unbelievable.

 

The control also doesn’t make it easy to extend in the HTML model. For example, Html Editing isn't supported so if you want to go down that path you're back to programming against HTML document element objects in slim COM wrappers.  I suppose I could probably figure out how to an interface reference to the raw browser events and fire those instead, but then I’m back to low level interfaces. Offhand I don’t remember what it takes to wrap these events manually (shit I was hoping I’d never have to look at that nasty code ever again).

 

Drat, this bugs me. Basically keeps me from using this control and stick with my old control...

 

Incidentally one of the reasons I even bothered updating this sample was because my Web Browser wasn't anchoring properly in the window. As it turns out the WinForms 2.0 control has the same behavior - it also oversizes itself by half a scrollbar...


The Voices of Reason


 

Rick Strahl
September 04, 2006

# re: WebBrowser Control – No PostData in Navigating Event

Some more information. I mentioned above that some parts of the OS didn't respect the font changes I made - it turns out that a reboot ended up making those changes.

The specific font to use for lists and sub window headers etc. apparently is the Icon text which I had originally missed.

As an aside using Tahoma even with ClearType on makes the UI look much sharper and more readable plus Tahoma 8 is a little smaller so it squeezes a little more information in lists etc. I know this is subjective, but it sure seems like a better setup to me...

Colin Neller
September 05, 2006

# re: WebBrowser Control – No PostData in Navigating Event

See if this discussion helps with your post data problem: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=7228&SiteID=1 . Regarding your anchoring problems, I usually just dock fill a WB in a panel (or a UserControl) and use the panel to do the anchoring. That usually get's around the problems I've had. Don't you just love the web browser control?

Rick Strahl
September 23, 2006

# re: WebBrowser Control – No PostData in Navigating Event

FWIW, there's a request for this this here:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=115580

Stop by there and vote on it if this is of interest to you.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2025