Currently, I'm seeing a strange behavior in my .NET 2.0 WinForms application.
Hosting a WebBrowser
control that pulls data from its own app-built-in web server (this one), everything works fine, until it comes to Google Web Fonts.
Steps:
Under Windows 7, the following behavior occurs:
1.) Start the application. The page does not display the Google Web Fonts:
2.) Open the URL of the built-in web server inside a stand-alone instance of Internet Explorer:
3.) Go back to the C# application, hit F5:
Now, the font is visible inside my application, too.
Behavior:
It seems that the stand-alone IE does additional things, that the hosted IE inside my application is not allowed to do.
Once the URL was opened inside the stand-alone IE, I can close both, my application and IE and restart my application and still get the correct behavior.
When clearing IE data (cache, cookies, etc.) the steps 1-3 are required again to get the Google Web Font into the hosted web browser.
My assumption:
I am guessing that this has something to do with permissions that IE seems to require to "install" the web font in its locale cache. I've just added a Access-Control-Allow-Origin:*
to my request header, but this does not seem to improve anything.
My question:
Do you have any hints on how to make Google Web Fonts working in my scenario, without the need to fire up the stand-alone IE?
Update 2013-08-22 - SOLUTION:
Based on Adam's suggestion, I changed the user agent of the WebBrowser
control and this worked. Now I do have web fonts inside my WinForms application with a hosted browser.
The code looks something like:
public void ChangeUserAgent()
{
// https://stackoverflow.com/a/12648705/107625
const string ua = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)";
// https://stackoverflow.com/q/937573/107625
UrlMkSetSessionOption(UrlmonOptionUseragent, ua, ua.Length, 0);
}
With those P/Invoke helper functions:
[DllImport(@"urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(
int dwOption,
string pBuffer,
int dwBufferLength,
int dwReserved);
private const int UrlmonOptionUseragent = 0x10000001;