How do you access the user agent from ActionFilterAttribute context?

450 views
0

I want to try and add some override code that will perform a specific action if the user making the request is using a particular user agent. I have the two following methods that are overridden from the base ActionFilterAttribute  class.

I have seen other tutorials where people are able to access properties of the request objects that I do not seem to be able to access here. This is for a webapi, so I am using System.Web.Http.Filters to implement the filter. The two context objects available in these methods don’t seem to be the same. How do I access additional request properties such as the user agent from this method.

Changed status to publish
0

The user agent is stored as part of the request object headers. You can access it using the following code.

 

Changed status to publish