How to access Request.Properties
in ActionExecutingContext
?
public class UserFilter : ActionFilterAttribute
{
public void OnActionExecuting(ActionExecutingContext actionContext)
{
// Properties is not part of the Request here, so I can't access it
// Here Request is of type System.Web.HttpRequestBase
actionContext.HttpContext.Request.Properties.Add("UserData", new UserData());
}
}
I can do it in ApiController
:
public class HomeController : ApiController
{
public HomeController()
{
// Here I can do it (here Request is of type
// System.Net.Http.HttpRequestMessage
this.Request.Properties.Add("UserData", new UserData());
}
}
For ApiController
you need use another ActionFilterAttribute
(located in System.Web.Http.Controllers
namespace):
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
public class UserFilter : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
// Properties is part of the Request here, you can access it
// actionContext.Request.Properties
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With