Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a HttpBrowserCapabilitiesBase from a UserAgent string
    text
    copied!<p>So the <a href="http://msdn.microsoft.com/en-us/library/system.web.httprequestbase.aspx">HttpRequestBase</a> class has a <a href="http://msdn.microsoft.com/en-us/library/system.web.httprequestbase.browser.aspx">Browser property</a> that returns a <a href="http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilitiesbase.aspx">HttpBrowserCapabilitiesBase</a>. We currently use this property in some of our MVC infrastructure code to get things like the Browser name and version number (for output to logs). </p> <p>We also have an api that uses <a href="http://www.servicestack.net/">ServiceStack</a>, and I would like to be able to hook this into our existing infrastructure. The only thing missing is being able to parse the browser name and version out of the UserAgent header (which I have thanks to the IHttpRequest.UserAgent), but need a way to parse it.</p> <p>My question - is it possible to create a HttpBrowserCapabilitiesBase somehow with just a UserAgent string? The only available subtype I see on msdn is <a href="http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilitieswrapper.aspx">HttpBrowserCapabilitiesWrapper</a>, whose sole ctor is another HttpBrowserCapabilitiesBase.</p> <p>I was thinking that this class probably solely parses the UserAgent string anyways, so why isn't there a ctor(string)?? Is there a subtype, factory or static method I am not seeing that can accomplish this?</p> <p>Generally I am just doing this for laziness - I don't want to write/find another UserAgent parser when I know .Net has that capability they are just hiding it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload