Name
UserAgent
Synopsis
stringvar = Request.UserAgent
Returns a String containing the User-Agent header. The User-Agent string identifies the browser (or other HTTP-capable client software, such as that used on mobile phones, etc.) the client uses to make the request. Depending on the browser and platform, this string may also identify the operating system the client uses, as well as the version of the installed .NET Framework (IE only).
Parameters
-
stringvar
A String variable to receive the User-Agent string.
Example
The example writes the UserAgent property to the browser:
Sub Page_Load( ) Dim stringvar As String stringvar = Request.UserAgent Message.Text = "User Agent: " & stringvar End Sub
Notes
When you attempt to discern the capabilities of the client browser,
using the properties of the HttpBrowserCapabilities object returned
by the Request.Browser property is generally easier. However, there
may be cases in which the User-Agent for a given client returns
information that is not checked for by the
HttpBrowserCapabilities
class. In this case, you
could add the desired information to the
<browserCaps>
configuration section handler
in machine.config
(see Chapter 8 and Chapter 20 for more
information on ASP.NET configuration) and then create your own
version of the HttpBrowserCapabilities
class by
inheriting from the built-in class and adding your own property or
properties for the User-Agent
attribute you’re looking for. Or, if you don’t want to make that effort, you could simply parse ...
Get ASP.NET in a Nutshell 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.