Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in a controller in asp.net-mvc how can i get information about the users browser?

I am logging errors on my asp.net-mvc site and I wanted to see if there is anyway to detect the users browser info (name, version, etc) as it seems like people are getting issue but its because they are using very old browser. This info would help me avoid debugging time if I know they are using a "Not supported" browser.

like image 605
leora Avatar asked Jun 10 '11 17:06

leora


People also ask

How do I access model data from a controller?

In Solution Explorer, right-click the Controllers folder and then click Add, then Controller. In the Add Scaffold dialog box, click MVC 5 Controller with views, using Entity Framework, and then click Add. Select Movie (MvcMovie. Models) for the Model class.

How can get current user in MVC controller?

If you need to get the user from within the controller, use the User property of Controller. If you need it from the view, I would populate what you specifically need in the ViewData , or you could just call User as I think it's a property of ViewPage .


2 Answers

You can get the supplied User Agent which gives browser information:

Request.UserAgent 

There is a site which lists browser user agent strings: http://www.useragentstring.com

Other values you may be interested in.

Request.Browser.Platform Request.Browser.Version Request.Browser.EcmaScriptVersion 
like image 192
Fosco Avatar answered Sep 20 '22 14:09

Fosco


You may try the Request.Browser property. It will contain pretty much everything you might need about the client browser (assuming it is sending the UserAgent header properly of course).

like image 43
Darin Dimitrov Avatar answered Sep 21 '22 14:09

Darin Dimitrov