Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to get browser information in ASP.NET

Author: Nikki Smith

In this article, I will show you how you can get browser information in ASP.NET application.

 

When you need browser information of your client in your ASP.NET application, you can simply get it by using HttpBrowserCapabilities class. This class enables server to get browser information that is running on the client side. This class needs System.Web namespace in your code file.

  1. Create a new Empty Web Site in Visual Studio 2010 either in Visual Basic or Visual C#.
  2. Add a Web Form in the Web Site and a Label control in the Web Form

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

     
  3. Write below code in Page Load method to get browser information

    Visual Basic
     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim browserInfo As HttpBrowserCapabilities = Request.Browser
        Label1.Text = "Browser Type: " & browserInfo.Type & "<br />"
        Label1.Text += "Browser Name: " & browserInfo.Browser & "<br />"
        Label1.Text += "Browser Version: " & browserInfo.Version & "<br />"
        Label1.Text += "Major Version: " & browserInfo.MajorVersion & "<br />"
        Label1.Text += "Minor Version: " & browserInfo.MinorVersion & "<br />"
        Label1.Text += "JavaScript Support: " & browserInfo.EcmaScriptVersion.ToString() & "<br />"
        Label1.Text += "VBScript Support: " & browserInfo.VBScript & "<br />"
        Label1.Text += "CSS Support: " & browserInfo.SupportsCss & "<br />"
        Label1.Text += "Platform: " & browserInfo.Platform & "<br />"
        Label1.Text += "Cookies Support: " & browserInfo.Cookies & "<br />"
        Label1.Text += "Tables Support: " & browserInfo.Tables & "<br />"
        Label1.Text += "Crawler: " & browserInfo.Crawler & "<br />"
        Label1.Text += "Frame Support: " & browserInfo.Frames & "<br />"
        Label1.Text += "ActiveXControl Support: " & browserInfo.ActiveXControls & "<br />"
    End Sub
     
    Visual C#
     
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpBrowserCapabilities browserInfo = Request.Browser;
        Label1.Text = "Browser Type: " + browserInfo.Type + "<br />"
        Label1.Text += "Browser Name: " + browserInfo.Browser + "<br />"
        Label1.Text += "Browser Version: " + browserInfo.Version + "<br />"
        Label1.Text += "Major Version: " + browserInfo.MajorVersion + "<br />"
        Label1.Text += "Minor Version: " + browserInfo.MinorVersion + "<br />"
        Label1.Text += "JavaScript Support: " + browserInfo.EcmaScriptVersion.ToString() + "<br />"
        Label1.Text += "VBScript Support: " + browserInfo.VBScript + "<br />"
        Label1.Text += "CSS Support: " + browserInfo.SupportsCss + "<br />"
        Label1.Text += "Platform: " + browserInfo.Platform + "<br />"
        Label1.Text += "Cookies Support: " + browserInfo.Cookies + "<br />"
        Label1.Text += "Tables Support: " + browserInfo.Tables + "<br />"
        Label1.Text += "Crawler: " + browserInfo.Crawler + "<br />"
        Label1.Text += "Frame Support: " + browserInfo.Frames + "<br />"
        Label1.Text += "ActiveXControl Support: " + browserInfo.ActiveXControls + "<br />"
    }
  4. Now you can see it in your browser
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to use nested GridView control in ASP.NET

Disclaimer - Privacy
© 2002-2014 DevASP.net