Click here to Skip to main content
12,956,197 members (89,193 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 24 Sep 2011

Navigate a Silverlight WebBrowser to a URL with a Hash (Fragment Identifier)

, 26 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
The Silverlight WebBrowser won't navigate to some URL's, but this can be worked around.
If you try to set the Silverlight WebBrowser control to navigate to|fr| either via the Source property in the XAML or by using the Navigate function, you will be presented with an exception (strangely, the Windows Forms WebBrowser has no problem with this URL). It seems the Uri class doesn't like to construct URLs that contain a pipe character in the hash (aka, fragment identifier) of the URL (the part of the URL that comes after the "#"). Here is the workaround:
string html = string.Format(
  @"<html><body><script type='text/javascript'>window.location = '{0}';</script></body></html>",

All you have to do is navigate to some HTML that has JavaScript that navigates to the URL you want the WebBrowser to visit. Here's the VB.NET version:
Dim html As String = String.Format(
  "<html><body><script type='text/javascript'>window.location = '{0}';</script></body></html>",

I suspect this is either a .NET bug in the implementation of Uri or pipe characters may not strictly be allowed in fragment identifiers. Whatever the reason, this is the workaround (though if somebody else has a more elegant solution, I would love to see it).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States

  • Managing Your JavaScript Library in ASP.NET (if you work with and you don't read that, you are dead to me).

  • Graduated summa cum laude with a BS in Computer Science.

  • Wrote some articles and some tips.

  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.

  • Software I have donated to (you should too):

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 26 Sep 2011
Article Copyright 2011 by AspDotNetDev
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid