title: ASP.NET HttpPost method returns "application/x-www-form-urlencoded is not supported"
body: <p>When I submit an HTTP POST message with <code>Content-Type:application/x-www-form-urlencoded</code> to my ASP.NET MVC controller method, it returns a response with HTTP error status code <code>415 Unsupported Media Type</code>, and the response body:</p>
  
  <p><code>{"Message":"The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource."}</code></p>
  
  <p>This error only occurs in my Production environment; the same code works as expected (i.e. the method code executes, and the method returns an HTTP 200 OK or an appropriate error) in my Staging and local development environments.</p>
  
  <p>Since the error occurs only in Production, with the same deployed code as my other environments, my guess is that this issue is being caused by some kind of environmental error -- for example, a problem with the configuration of my Production application in IIS, or a filesystem permissions problem somewhere in the Production app's directory -- but I'm not sure where to look.</p>
  
  <p><strong>My Code</strong></p>
  
  <p>My controller method:</p>
  
  <pre><code>[HttpPost]
  [Route("Account/Login")]
  public AccessTokenDTO Login([FromBody] AccountDTO account)
  {
      // (Returns an AccessTokenDTO if the credentials are good; 
      // otherwise throws an HttpResponseException with a 401.)
  }
  </code></pre>
  
  <p>The simple AccountDTO class, in case it matters:</p>
  
  <pre><code>public class AccountDTO
  {
      [Required]
      public string Username { get; set; }
      [Required]
      public string Password { get; set; }
  }
  </code></pre>
  
  <p><strong>Server HTTP Response</strong></p>
  
  <p>The Production environment's unexpected HTTP 415 error response includes the following HTTP headers and values:</p>
  
  <pre><code>Cache-Control: no-cache
  Pragma: no-cache
  Content-Type: application/json; charset=utf-8
  Expires: -1
  Server: Microsoft-IIS/7.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Thu, 25 Feb 2016 16:28:16 GMT
  Content-Length: 117
  </code></pre>
  
  <p>The exact same set of headers and values (except for the <code>Date</code> and <code>Content-Length</code> values) are returned when the request succeeds, i.e. when I submit it to my Staging URL instead of my Production URL.</p>
  
  <p><strong>Client HTTP Request</strong></p>
  
  <p>In addition to seeing the error fail when called from my actual client program, I'm using the Firefox extension <a href="https://addons.mozilla.org/en-US/firefox/addon/poster/" rel="nofollow">Poster</a> to submit the HTTP POST and inspect the response.  The request URL looks like:</p>
  
  <pre><code>https://[myserver].com/[mypath1]/[mypath2]/Account/Login
  </code></pre>
  
  <p>Request headers:</p>
  
  <pre><code>Content-Type: application/x-www-form-urlencoded
  </code></pre>
  
  <p>Request body: </p>
  
  <pre><code>Username=my-urlencoded-username&amp;Password=my-urlencoded-password
  </code></pre>
  
  <p><strong>My Question</strong></p>
  
  <p>For what reason might ASP.NET be returning the <code>"The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource."</code> error, but only in one of my environments?</p>