Detecting which version of IE is installed on your

2019-06-24 03: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.

2条回答
我只想做你的唯一
2楼-- · 2019-06-24 04:18

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.

查看更多
在下西门庆
3楼-- · 2019-06-24 04:35

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

查看更多
登录 后发表回答