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.
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) public override void OnActionExecuting(HttpActionContext actionContext)
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.
1 Answer
The user agent is stored as part of the request object headers. You can access it using the following code.
actionContext.Request.Headers.UserAgent.ToString()
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String