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:
Use the
Browser
property of theRequest.Browser
object to return a string representing the full browser type, such as “IE” in the case of Internet Explorer.Use the
Version
property of theRequest.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.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.
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 ...
Get ASP.NET Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.