I created an ActionFilterAttribute for my web api in order to authorize people. Getting accessToken by RequestUri is okay, however i want to send it in form data. While reading
It's is because the HttpContent has been read by the formatter before ActionFilter. Web API only allows reading content once. So you are unable to read it again.
Here is a possible solution to you. First, make your action parameter as FormDataCollection:
[RequireAuthorization]
public HttpResponseMessage PostTodo(FormDataCollection formData)
{
Todo todo = formData.ReadAs<Todo>();
// ...
Then, get it in ActionFilter by code:
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var formData = actionContext.ActionArguments["formData"] as FormDataCollection;
if (formData != null)
{
var userID = formData.Get("UserID");
var accessToken = formData.Get("AccessToken");
// authorize
}
base.OnActionExecuting(actionContext);
}