O'Reilly logo

ASP.NET Cookbook by Geoffrey T. LeBlond, Michael A Kittel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.4. Determining the User’s Browser Type

Problem

Your application requires the use of a specific browser and you want to determine whether the required browser is being used before allowing a user to access your application.

Solution

Use the properties of the Request.Browser object to determine the browser type and version, and then take the action required by your application.

In the code-behind class for the page, use the .NET language of your choice to:

  1. Use the Browser property of the Request.Browser object to return a string representing the full browser type, such as “IE” in the case of Internet Explorer.

  2. Use the Version property of the Request.Browser object to return a string that represents the major and minor version of the browser, such as “6.0” in the case of IE 6.0.

  3. Take action accordingly, such as outputting a message indicating whether the user’s browser is compatible with the application.

Example 18-10 through Example 18-12 show the .aspx file and the VB and C# code-behind files for an application that demonstrates the solution. The output of our example program is shown in Figure 18-2.

Determining the user’s browser

Figure 18-2. Determining the user’s browser

Discussion

With the variety of different browsers in use today and the significant variation in their capabilities, it is not uncommon to need to determine the type of browser being used. Then, based on the browser, you may need to inform the user ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required