What is the difference between Request.UserAgent and Request.Browser?

Here is my code below:

User_Info.Add(!string.IsNullOrEmpty(Request.UserAgent) ? Request.UserAgent : string.Empty);//4:UserAgent HttpBrowserCapabilities browser = Request.Browser; User_Info.Add(!string.IsNullOrEmpty(browser.Browser) ? "Name : " + browser.Browser + " | " + "Type : " + browser.Type + " | " + "MajorVersion : " + browser.MajorVersion + " | " + "MinorVersion : " + browser.MinorVersion : string.Empty);//5:UserBrowser 

What is the difference between Request.UserAgent and Request.Browser?
I could not understand these lines UserAgent!
Could you show some examples with an explanation?

+7
source share
3 answers

Request.Browser is different from Request.UserAgent. The UserAgent receives the string of the original user agent of the client browser, and Request.Browser provides you with information about the capabilities of the browser. You will not get all the features of a browser with the UserAgent string .

+7
source

UserAgent gives you the raw browser string. It might look like this:

User Agent :: Mozilla / 4.0 (compatible; MSIE 6.0b; Windows NT 5.1; CLR 1.0.2914)

Request.Browser will provide you with an HttpBrowserCapabilities object that will have browser version information as well as additional information about browser capabilities. For example:

  • Does the browser support Frames
  • Should it support cookies?
  • Supports JavaScripts?
  • Supports Java applets? and etc.

See the following code example:

 HttpBrowserCapabilities bc = Request.Browser; Response.Write("<p>Browser Capabilities:</p>"); Response.Write("Type = " + bc.Type + "<br>"); Response.Write("Name = " + bc.Browser + "<br>"); Response.Write("Version = " + bc.Version + "<br>"); Response.Write("Major Version = " + bc.MajorVersion + "<br>"); Response.Write("Minor Version = " + bc.MinorVersion + "<br>"); Response.Write("Platform = " + bc.Platform + "<br>"); Response.Write("Is Beta = " + bc.Beta + "<br>"); Response.Write("Is Crawler = " + bc.Crawler + "<br>"); Response.Write("Is AOL = " + bc.AOL + "<br>"); Response.Write("Is Win16 = " + bc.Win16 + "<br>"); Response.Write("Is Win32 = " + bc.Win32 + "<br>"); Response.Write("Supports Frames = " + bc.Frames + "<br>"); Response.Write("Supports Tables = " + bc.Tables + "<br>"); Response.Write("Supports Cookies = " + bc.Cookies + "<br>"); Response.Write("Supports VB Script = " + bc.VBScript + "<br>"); Response.Write("Supports JavaScript = " + bc.JavaScript + "<br>"); Response.Write("Supports Java Applets = " + bc.JavaApplets + "<br>"); Response.Write("Supports ActiveX Controls = " + bc.ActiveXControls + "<br>"); Response.Write("CDF = " + bc.CDF + "<br>"); 

To compare the version of the browser with the user agent, you have to use string operations (Contains), while in the case of Request.Browser you can compare it with the property.

+11
source

Request.UserAgent is a little cryptic and requires parsing to determine which browser, in particular, the visitor is using. In addition, it does not contain information, such as the JavaScript version supported by the browser, or if the browser supports CSS 2.0 styles

The Request.Browser property is an instance of the HttpBrowserCapabilities object that provides all the information ...

Link: http://www.4guysfromrolla.com/articles/120402-1.aspx

+1
source

All Articles