Last post Dec 01, 2015 02:53 PM by jbowen014
Dec 01, 2015 01:57 PM|jbowen014|LINK
In previous versions of ASP .NET, browser information was available by accessing Request.Browser. Is there an equivalent in ASP .NET 5? I want to capture information such as Browser Name and Version for requests. I am capturing the user-agent, but that is
unpleasant to parse.
Dec 01, 2015 02:25 PM|Rion Williams|LINK
Is there any particular reason that you are trying to access this within your server-side code? This type of information should generally be handled client-side if you are going to be doing anything with it (i.e. responsive design, etc.), so that is something
Previously .NET would rely on underlying .browser files in order to use properties like Request.Browser, however these are no longer present within the .NET 5 ecosystem. As a result of this, you'll really have to rely on what you can access, namely the User
Agent property. The User Agent should have all of the information that you need with regards to the browser and specific version, but as you mention it can be a pain to parse. You could implement some type of heuristic that would check for a certain value
being present in the User Agent and use it to output the appropriate type or you could look into a library that could handle this for you like
If we have more information about why you need the browser at this point, it might make it easier to recommend how to best tackle it.
Dec 01, 2015 02:34 PM|jbowen014|LINK
Thanks for the quick response. I only need the information server side for logging. I have a requirement to log all incoming requests to the application, and having the Browser Name and Browser Version stored in separate columns in the database table is
convenient for reporting purposes.
Dec 01, 2015 02:51 PM|Rion Williams|LINK
You'll definitely need to use a parser to handle this (which is what the previous version of ASP.NET did for the Request.Browser object). You could try using an implementation like the one in
this open-source User Agent Parser project from GitHub.
Dec 01, 2015 02:53 PM|jbowen014|LINK
Thank you so much for your help! The UAParser nuget package worked perfectly.