What’s the browser?

Question: I was watching you recent Web cast on Developing Mobile Applications with ASP.NET. You mentioned that it was possible to capture information about the incoming browser request to see what types of features it may support. Any chance you could give me a short example before then?

Answer: Sure but you have to still promise to attend the remaining two sessions! It’s actually pretty easy using the .NET Framework HttpBrowserCapabilities Class . This class enables the server to gather information on the capabilities of the browser that is running on the client. It contains a variety of properties that enables you to view properties on the incoming browser.

As an example, place the following code within an ASP.NET page.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim bc As HttpBrowserCapabilities = Request.Browser

        Response.Write("<p>Browser Capabilities:</p>")

        Response.Write("Type = " & bc.Type & "<br>")

        Response.Write("Name = " & bc.Browser & "<br>")

        Response.Write("Version = " & bc.Version & "<br>")

        Response.Write("Major Version = " & bc.MajorVersion & "<br>")

        Response.Write("Minor Version = " & bc.MinorVersion & "<br>")

 

        Response.Write("Is a Mobile Browser = " & bc.IsMobileDevice & "<br>")

        Response.Write("Mobile Device Manufacturer = " & bc.MobileDeviceManufacturer & "<br>")

        Response.Write("Mobile Device Model = " & bc.MobileDeviceModel & "<br>")

        Response.Write("Is a Mobile Browser = " & bc.IsMobileDevice & "<br>")

        Response.Write("Number of soft keys = " & bc.NumberOfSoftkeys & "<br>")

      

        Response.Write("Platform = " & bc.Platform & "<br>")

        Response.Write("Is Beta = " & bc.Beta & "<br>")

        Response.Write("Is Crawler = " & bc.Crawler & "<br>")

        Response.Write("Is AOL = " & bc.AOL & "<br>")

        Response.Write("Is Win16 = " & bc.Win16 & "<br>")

        Response.Write("Is Win32 = " & bc.Win32 & "<br>")

        Response.Write("Supports Frames = " & bc.Frames & "<br>")

        Response.Write("Supports Tables = " & bc.Tables & "<br>")

        Response.Write("Supports Cookies = " & bc.Cookies & "<br>")

        Response.Write("Supports VB Script = " & bc.VBScript & "<br>")

        Response.Write("Supports JavaScript = " & bc.EcmaScriptVersion.ToString & "<br>")

        Response.Write("Supports Java Applets = " & bc.JavaApplets & "<br>")

        Response.Write("Supports ActiveX Controls = " & bc.ActiveXControls & "<br>")

        Response.Write("CDF = " & bc.CDF & "<br>")

    End Sub

When run this shows the following for

Standard IE running on the desktop

Pocket IE running on the Windows Mobile 5 Emulator

OpenWave 7.0 SDK

OpenWave 6.2.2 SDK