views:

57

answers:

4

What is the IE6 equivalent to Request.UserAgent.ToLower().Contains("msie")?

As above it detects any instance of IE obviously, but I'm looking to only pull IE6 users so I can display a message telling them the site will render oddly in their browsers. I haven't been able to find the answer in my searches.

A: 

Does this help?

Request.UserAgent.ToLower().Contains("msie 6.0");

This MSDN help doc shows that MSIE 6.0 is within the user agent string for IE6.

p.campbell
+3  A: 

Don't.

Either

Use conditional comments instead. That's the proper way to target versions of IE.

Output this directly to the web page:

<!-- [if lte IE 6]
<div id="ie6div">This page may not behave correctly in your browser. I suggest you <a href="http://browserupdate.org"&gt;update&lt;/a&gt; your browser.</div>
-->

Or

Use the browser update javascript:

<script type="text/javascript"> 
var $buoop = {} 
$buoop.ol = window.onload; 
window.onload=function(){ 
 if ($buoop.ol) $buoop.ol(); 
 var e = document.createElement("script"); 
 e.setAttribute("type", "text/javascript"); 
 e.setAttribute("src", "http://browser-update.org/update.js"); 
 document.body.appendChild(e); 
} 
</script> 

It's generally agreed that parsing the User-Agent string is evil.

TRiG
Another more obtrusive update JavaScript: http://code.google.com/p/sevenup/
Nelson
+1  A: 

You can detect IE6 like so:

if (Request.UserAgent.IndexOf("MSIE 6.0") > -1) 
{
   // The browser is Microsoft Internet Explorer Version 6.0.
}

However, you probably don't want to do that. Better to handle this on the client side using jQuery (now supported officially by Microsoft) and use feature (object) detection instead of browser version number detection which will make your code more robust and future proof.

GeneQ
Gosh that looks strangely similar to the MSDN article's implementation!
p.campbell
@p.campbell MSDN is my friend. ;-)
GeneQ
A: 

If you really need to detect the browser server-side, use Request.Browser.Type, it returns "IE6" for IE6!

Willem
thanks everyone for your help and advice, ultimately i can only choose one right answer and this one most directly answered it correctly
korben