Internet Explorer 7 User Agent String

Internet Explorer 7 Beta 1 is fast approaching.  A tiny but significant code change was checked in this week: Internet Explorer's new User-Agent string. 

The User-Agent (or UA) string is sent along in the headers of every HTTP request so the server knows what type of browser is making the request.  For a quick introduction on handling of the User-Agent string, check out George Shephard's article in MSDN Magazine.

Internet Explorer 7 User-Agent

As we updated the User-Agent, we considered application-compatibility issues, historical precedent, and feedback from the community.  We arrived at a very simple string.

IE7 running on Longhorn will send the following User-Agent header: Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)

There are three points of interest in this string:

  1. We updated from 6.0 to 7.0 to reflect the new application version.
  2. Consistent with prior betas, a "b" was added following the 7.0, in order to flag this as a beta release.  This "b" will be removed for RTM.
  3. The "SV1" token was removed.  As predicted by the community, this token becomes redundant with the release of IE7.

What does this mean for web developers?

If you use ASP.NET's HTTPBrowserCapabilities class on your pages, you'll find that it is already able to correctly interpret the new UA string.  The class will return 7 for the MajorVersion property, and True for the Beta property.

Checks for the IE security features introduced in XP SP2 can be updated as follows:

    System.Web.HttpBrowserCapabilities browser = Request.Browser;
bool isIESecurityEnhanced = (browser.Browser == "IE" && (browser.MajorVersion > 6 ||
(browser.MajorVersion == 6 && Request.Headers["User-Agent"] != null && Request.Headers["User-Agent"].IndexOf("SV1")>-1)));

Can web developers test the new string out before IE7 Beta ships?

My first suggestion was to use a simple rule in Fiddler to change the outbound User-Agent header:

static function OnBeforeRequest(oSession:Fiddler.Session){
oSession.oRequest["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)";
}

However, this will only report the new User-Agent to the web server; any script in the webpage that calls the navigator object to check the browser version will never notice this change.  Rats.

Fortunately, IE5.0 and later allow you to override the user-agent string used by scripting and sent by the browser.

Simply save the following as IE7UA.REG.  Double-click the file to merge it into your registry and restart the browser to see the change.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInternet Settings5.0User Agent]
"Version"="MSIE 7.0b"

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInternet SettingsUser AgentPost Platform]
"SV1"=-

You can easily undo the change by saving and merging the following IE7Undo.reg.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInternet Settings5.0User Agent]
"Version"=-

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInternet SettingsUser AgentPost Platform]
"SV1"=""

You can test the change using a simple page that echos the User-Agent, e.g.: https://www.fiddlertool.com/useragent.aspx.

-Eric Lawrence