问题描述
使用Web浏览器控件一段时间后,由于我遇到的Web浏览器问题,速度慢和性能下降,我决定尝试壁虎.我下载了最新版本的geckofx(16.0.0.2)和xulrunner(16.0.2),并创建了一个geckoWebbrowser控件.当我尝试导航到网页时,我得到了一个javascript.alert,我的网络浏览器不受支持,我应该使用firefox> 2.0.0.2,这当然是荒谬的.问题是-我假设-检测到的用户代理字符串是"Mozilla/5.0(Windows NT 6.1; WOW64; rv:16.0)Gecko//16.0",而不是普通的Firefox字符串"Mozilla/5.0(Windows NT 6.1; WOW64;rv:18.0)Gecko/20100101 Firefox/18.0.控件的useragent字符串中缺少"20100101"和"Firefox".有什么办法可以使用C#进行更改吗?我使用C#winforms .net 4.5.
After using the webbrowser control for some time, I decided to give gecko a try, because of the webbrowser's problems that I've experienced, low speed and degrading performance. I downloaded the latest version of geckofx (16.0.0.2) and xulrunner(16.0.2) and created a geckoWebbrowser control. When I tried to navigate to a webpage I got a javascript.alert that my web browser is not supported and that I should use firefox>2.0.0.2 which of course is ridiculous.The problem was - I assume - that the detected useragent string was "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/ /16.0" instead of the normal firefox string "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0". '20100101' and 'Firefox' are missing from the control's useragent string. Is there any way to change it using C#?I use C# winforms .net 4.5.
推荐答案
来自 http://www.webprogrammingblog.com/geckofx-set-user-agent/:
public Form1()
{
InitializeComponent();
Gecko.Xpcom.Initialize("c:\\tools\\xulrunner");
myBrowser = new GeckoWebBrowser();
myBrowser.Parent = this;
myBrowser.Dock = DockStyle.Fill;
string sUserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; pl; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)";
Gecko.GeckoPreferences.User["general.useragent.override"] = sUserAgent;
}
这篇关于如何在GeckoFX中设置用户代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!