Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

HOW TO: Determine the Browser Version in ASP.NET


View products that this article applies to.

This article was previously published under Q311281

↑ Back to the top


Summary

This article describes how to determine the Web browser version in ASP.NET.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
  • Visual Studio .NET
  • Microsoft Internet Information Services (IIS)
This article assumes that you are familiar with the following topics:
  • Visual Studio .NET
  • Microsoft .NET Framework

Determine the Browser Version

ASP.NET introduces the HttpBrowserCapabilities class to gather information during an HTTP request about the capabilities of the browser. HttpBrowserCapabilities informs your program about the type and level of support that the browser offers and can be accessed by querying the HttpRequest.Browser property.

The HttpBrowserCapabilities class includes properties such as Browser, MajorVersion, and MinorVersion to help describe the browser. Previously, ASP used the Browser Capabilities component (Browscap.dll) to access the capabilities of the browser by comparing the User-Agent HTTP header with the entries in the Browscap.ini file. The information in the Browscap.ini file is now stored in a configuration file in ASP.NET. By default, the browserCaps element in machine.config stores all of the settings of the Browser Capabilities componenet.

The following sample uses HttpBrowserCapabilities to determine the browser information:
  1. Start Visual Studio .NET.
  2. Create a new ASP.NET Web Application in Microsoft Visual Basic .NET.
  3. Switch to Design view.
  4. Add a Server button and Server text box. By default, these are named Button1 and TextBox1.
  5. Change the Server text box TextMode property to MultiLine, and then extend the width and height of the text box.
  6. Double-click Button1.
  7. In the Code window for the Button1_Click event, add the following code:

    VB .NET

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim bc As HttpBrowserCapabilities
            Dim s As String = ""
            bc = Request.Browser
            With bc
                s &= "Browser Capabilities" & vbCrLf
                s &= "Type = " & .Type & vbCrLf
                s &= "Name = " & .Browser & vbCrLf
                s &= "Version = " & .Version & vbCrLf
                s &= "Major Version = " & .MajorVersion & vbCrLf
                s &= "Minor Version = " & .MinorVersion & vbCrLf
                s &= "Platform = " & .Platform & vbCrLf
                s &= "Is Beta = " & .Beta & vbCrLf
                s &= "Is Crawler = " & .Crawler & vbCrLf
                s &= "Is AOL = " & .AOL & vbCrLf
                s &= "Is Win16 = " & .Win16 & vbCrLf
                s &= "Is Win32 = " & .Win32 & vbCrLf
                s &= "Supports Frames = " & .Frames & vbCrLf
                s &= "Supports Tables = " & .Tables & vbCrLf
                s &= "Supports Cookies = " & .Cookies & vbCrLf
                s &= "Supports VB Script = " & .VBScript & vbCrLf
                s &= "Supports JavaScript = " & .JavaScript & vbCrLf
                s &= "Supports Java Applets = " & .JavaApplets & vbCrLf
                s &= "Supports ActiveX Controls = " & .ActiveXControls & vbCrLf
            End With
            TextBox1.Text = s
    End Sub
    					

    Visual C#

    private void Button1_Click(object sender, System.EventArgs e)
    {
    HttpBrowserCapabilities bc;
            string s;
            bc = Request.Browser;
    s= "Browser Capabilities" + "\n";
                s += "Type = " + bc.Type + "\n";
                s += "Name = " + bc.Browser + "\n";
                s += "Version = " + bc.Version + "\n";
                s += "Major Version = " + bc.MajorVersion + "\n";
                s += "Minor Version = " + bc.MinorVersion + "\n";
                s += "Platform = " + bc.Platform + "\n";
                s += "Is Beta = " + bc.Beta + "\n";
                s += "Is Crawler = " + bc.Crawler + "\n";
                s += "Is AOL = " + bc.AOL + "\n";
                s += "Is Win16 = " + bc.Win16 + "\n";
                s += "Is Win32 = " + bc.Win32 + "\n";
                s += "Supports Frames = " + bc.Frames + "\n";
                s += "Supports Tables = " + bc.Tables + "\n";
                s += "Supports Cookies = " + bc.Cookies + "\n";
                s += "Supports VB Script = " + bc.VBScript + "\n";
                s += "Supports JavaScript = " + bc.JavaScript + "\n";
                s += "Supports Java Applets = " + bc.JavaApplets + "\n";
                s += "Supports ActiveX Controls = " + bc.ActiveXControls + "\n";
            TextBox1.Text = s;
    
    }
    					
  8. Run the project and click the button. The text box lists information about your browser.

↑ Back to the top


References

For more information, visit the following Microsoft Web sites. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
167820� HOWTO: Determine Browser Version from a Script
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB311281, kbhowtomaster, kbbrowse, kbwebforms

↑ Back to the top

Article Info
Article ID : 311281
Revision : 8
Created on : 4/19/2007
Published on : 4/19/2007
Exists online : False
Views : 520