21.4. Determining the User’s Browser Type


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


Use the properties of the Request.Browser object to determine the browser type and version, and 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.

Examples 21-10, 21-11 through 21-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 21-2.

Determining the user’s browser

Figure 21-2. Determining the user’s browser


With different browsers in use today and the significant variation in their capabilities, determining the type of browser being used is common. Based on the browser, you may need to inform the user that the browser is incompatible with your application ...

Get ASP.NET 2.0 Cookbook, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.