title: MVC Api Action & System.Web.Http.AuthorizeAttribute - How to get post parameters?
body: <p>I have the following API Controller:</p>
  
  <pre><code>public class TestController : ApiController
  {
      [HttpPost]
      [APIAuthorizeAttribute]
      public IQueryable&lt;Computers&gt; ListOfComputersInFolder(Guid folderId)
      {
          return GetListOfComputersForFolder(folderId);
      } // End of ListOfComputersInFolder
  } // End of TestController 
  </code></pre>
  
  <p>And the following is my basic <code>APIAuthorizeAttribute</code>.</p>
  
  <pre><code>public class APIAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
  {
      public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
      {
          var Request = System.Web.HttpContext.Current.Request;
          var folderId = Request.RequestContext.RouteData.Values["folderId"] ?? Request.Params["folderId] as string;
          if(null == folderId)
          {
              folderId = actionContext.ControllerContext.RouteData.Values["folderId"];
          }
  
          base.OnAuthorization(actionContext);
      }
  }
  </code></pre>
  
  <p>The problem that I'm having is that <code>folderId</code> is coming out null in the onAuthorize method. (I based the fetcher on <a href="https://stackoverflow.com/questions/5225551/reference-generic-url-parameter-in-authorizeattribute">this</a> code).</p>
  
  <p>It seems to me that this should be working, but I cannot seem to get it to. Any ideas on what I am doing wrong and how I should go about getting the posted parameter?</p>
  
  <p>Edit: I tried reading the post data directly with the following:</p>
  
  <pre><code>using (StreamReader inputStream = new StreamReader(request.InputStream))
  {
      output = inputStream.ReadToEnd();
  }
  request.InputStream.Position = 0;
  </code></pre>
  
  <p>Which gets me the post data in JSON format which I could then parse, but then my call never makes it though. I get the following exception in the Response:</p>
  
  <pre><code>  &lt;h2&gt;500 - Internal server error.&lt;/h2&gt;
    &lt;h3&gt;There is a problem with the resource you are looking for, and it cannot be displayed.
  
  at System.Json.JXmlToJsonValueConverter.JXMLToJsonValue(Stream jsonStream, Byte[] jsonBytes)\u000d\u000a   at System.Net.Http.Formatting.JsonMediaTypeFormatter.&lt;&gt;c__DisplayClass7.&lt;OnReadFromStreamAsync&gt;b__6()\u000d\u000a   at System.Net.Http.Internal.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}
  </code></pre>
  
  <p>EDIT:
  In the end, it seems like this could possibly be a bug with the combination of <code>ApiController</code>, <code>System.Web.Http.AuthorizeAttribute</code> and <code>HttpPost</code> (it does work when using <code>HttpGet</code>). A bug report has been submitted.</p>