Detecting which version of IE is installed on your OS in C#?

若如初见. 提交于 2019-12-23 12:38:33

问题


I am currenting manintaining a windows service that programmatcially generates a HttpWebRequest and HttpWebResponse objects for retrieving the response message of the request.

The UserAgent property of the HttpWebRequest was hard coded to use IE 6 as the browser agent. Is the a way to programmatcially detect which version of IE is installed on the server hosting the service?

It is currently hosted on a Windows Server 2003 machine and might be installed on a Windows Server 2008 machine.


回答1:


you can also extract it from the WebBrowser control itself, if you have created one:

WebBrowser  browser = new WebBrowser();
Version ver = browser.Version;

Warning: this must be called from STA thread, otherwise it throws an exception. This can be encountered in MSTest cleanup code, which is MTA, not STA.




回答2:


It looks like the user agent can be set: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent.aspx

I prefer the WebClient class these days, it's a wrapper for HttpWebRequest and allows you to do some things with less code: http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx



来源:https://stackoverflow.com/questions/850709/detecting-which-version-of-ie-is-installed-on-your-os-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!