Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 couldn't understand those UserAgent strings!
Would you please show some examples with explanation?

like image 504
SilverLight Avatar asked May 28 '12 06:05

SilverLight


People also ask

What is userAgent in Httpwebrequest?

The User Agent is used to identify the client and operating system etc.

What is my userAgent?

In simple words, it's a string of text that is unique for each software or browser on the internet and holds the technical information about your device and operating system. User-agent is present in the HTTP headers when the browser wants to connect with the webserver.

What is AppleWebKit used for?

AppleWebKit/537.36 indicates what browser rendering engine is used. A rendering engine is what transforms HTML into an interactive webpage on the user's screen.

What is browser identification?

“A device fingerprint, machine fingerprint, or browser fingerprint is information collected about a remote computing device for the purpose of identification. Fingerprints can be used to fully or partially identify individual users or devices even when cookies are turned off.”


2 Answers

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

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

Request.Browser will give you HttpBrowserCapabilities object which will have browser version information along with some extra information regarding the capabilities of the browser. For example:

  1. Whether browser supports Frames
  2. If it supports cookies ?
  3. Supports JavaScripts ?
  4. Supports Java Applets ? etc.

Look at the following sample code:

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>");

For comparing browser version against a user agent, you would have to use string operations (Contains), whereas in case of Request.Browser you can compare against a property.

like image 76
Habib Avatar answered Oct 20 '22 20:10

Habib


Request.Browser is different from Request.UserAgent. UserAgent gets the raw user agent string of the client browser, and Request.Browser gets you the information about the browser capabilities. You wont get all the browser capabilities with the UserAgent string.

like image 42
Asif Mushtaq Avatar answered Oct 20 '22 18:10

Asif Mushtaq