5

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());
    }
}
0

2 Answers 2

2

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
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

-1

actionContext.ActionDescriptor.Properties.Add("UserData", new UserData());

1 Comment

How does this help? you seem to just be adding a random object?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.