Microsoft Knowledge Base Email Alertz

KBAlertz.com: This step-by-step article demonstrates how to determine the client browser type in server-side code without using the

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 306576 - Last Review: December 27, 2005 - Revision: 3.4

How to determine browser type in server-side code without the BrowserType object in ASP.NET

This article was previously published under Q306576

On This Page

SUMMARY

This step-by-step article demonstrates how to determine the client browser type in server-side code without using the BrowserType object in ASP.NET.

In classic Microsoft Active Server Pages (ASP), the two most common methods to determine the client browser type are to use the BrowserType component or the Request.ServerVariables("HTTP_USER_AGENT") variable. Although you can use these methods in ASP.NET, you can also use the new properties that ASP.NET provides. In ASP.NET, the Request object includes a property named Browser that contains rich information about client browser capabilities such as browser name, browser version, and whether JavaScript, ActiveX controls, cookies, and frames are supported.

NOTE: This article assumes that you have ASP.NET and Visual Studio .NET installed on your computer.

Using the HTTP_USER_AGENT Header to Determine the Browser Version

In ASP.NET, you can access the Request.ServerVariables collection or use the new Request.UserAgent property to retrieve the HTTP_USER_AGENT header value. You can parse this string to determine the browser name, the major and minor versions of the browser, and if the browser is a beta release.

The following list includes two sample user agent strings:
  • When you browse with Microsoft Internet Explorer 6.0 Beta, you may receive a user agent string similar to the following:
    User Agent :: Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914)
  • When you browse with Internet Explorer 5.5, you may receive the following user agent string:
    User Agent :: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
For more information about parsing the User Agent variable, click the following article number to view the article in the Microsoft Knowledge Base:
272413  (http://kbalertz.com/Feedback.aspx?kbNumber=272413/ ) How to determine browser type in server-side script without the BrowserType object

Using the Request.Browser Object to Determine the Browser Version

In ASP.NET, the Request object contains a property named Browser that returns an object of type HttpBrowserCapabilities. This object contains properties such as browser, version, major version, and minor version that you can use to determine the client browser type.

Follow these steps to create a simple ASP.NET application using Visual Basic .NET that writes the browser name and versions back to the client browser in HTML:
  1. From the Start menu, point to Programs, point to Microsoft Visual Studio.NET, and click Microsoft Visual Studio.NET.
  2. Click New Project.
  3. In the New Project dialog box, under Project Type, click Visual Basic Projects. Under Templates, click ASP.NET Web Application. In the Name text box, type a name for the application.
  4. Double-click in the Design window of Webform1.
  5. Replace the code for the Page_Load event with the following code:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MyBase.Load
            Response.Write("<B>User Agent ::</B> " & Request.UserAgent & "<BR>")
            Response.Write("<B>Browser ::</B> " & Request.Browser.Browser & "<BR>")
            Response.Write("<B>Version ::</B> " & Request.Browser.Version & "<BR>")
            Response.Write("<B>Major::</B> " & Request.Browser.MajorVersion() & "<BR>")
            Response.Write("<B>Minor::</B> " & Request.Browser.MinorVersion() & "<BR>")
        End Sub
    					
  6. Press the CTRL+S key combination to save the file.
  7. On the Build menu, click Build.
  8. After the build is complete, either click Start, or right-click Webform1.aspx in Solution Explorer, and then click View in Browser.
  9. In the browser window, notice that the User Agent string appears and includes the browser name, version, major versions, and minor versions.

APPLIES TO
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
Keywords: 
kbbrowse kbhowtomaster kbwebforms KB306576
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please