Detecting and Responding to Browser Version

Topics: ASP.NET 2.0, Business Logic Layer, Themes
Jun 25, 2009 at 3:07 AM

I recently upgraded my browser to IE8, and noticed that the png files I include in my blog render significantly cleaner without any visual noise or aliasing. Upon checking, I noticed that this is also true for the latest versions of Google Chrome and Safari, but not for Firefox. Since I include a lot of graphics in my blog, I decided to give users a little nudge to upgrade via a notice at the end of the PostView.ascx rendering. I'm passing along the code, in case it is of use to anybody else...

          HttpBrowserCapabilities bc = Request.Browser;
          if (bc.Type!="IE8" && bc.Type!="Desktop") // Desktop is the browser type reported by Google Chrome and Safari
                Response.Write("<p style=\"text-align:center;\">You are using "+bc.Type+". This site's graphics display well in "
                              +"<a href=\"\" title=\"Download IE8\">Internet Explorer 8</a>; "
                              +"<a href=\"\" title=\"Download Safari\">Safari</a>; and, "
                              +"<a href=\"\" title=\"Download Google Chrome\">Google Chrome</a>.</p>");

The above code I put immediately before the end of the "bookmarks" division. Curiously, both Google Chrome and Safari identify themselves as "Desktop." Not sure why.