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:
Browserproperty of the
Request.Browserobject to return a string representing the full browser type, such as
IEin the case of Internet Explorer.
Versionproperty of the
Request.Browserobject to return a string that represents the major and minor version of the browser, such as
6.0in 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.
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.
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 ...