title: Razor Pages POST handler returns 404 on IIS
body: <p>I am working on an ASP.NET Core 2.1 application. I need to call a named page handler through ajax.</p>
  
  <p>The method works correctly while in debug/release, but fails once it is published to IIS.</p>
  
  <h3>What I have tried</h3>
  
  <ul>
  <li>I am now using @page "{handler?}" instead of specifying the handler as a query parameter</li>
  <li>I have made sure that the request url is correct, and that the form contains the "__RequestVerificationToken"</li>
  <li>I have changed the IIS Application Pool CLR Version to "No Managed Code"</li>
  <li>I have modified my web.config to look like this:</li>
  </ul>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;location path="." inheritInChildApplications="false"&gt;
          &lt;system.webServer&gt;
              &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
              &lt;handlers&gt;
                  &lt;add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /&gt;
              &lt;/handlers&gt;
              &lt;aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /&gt;
          &lt;/system.webServer&gt;
      &lt;/location&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <h3>Code:</h3>
  
  <p>This is the handler method, there are similar ones in other pages and none of them is found by the ajax request (but again, this only happens once it is deployed to IIS):</p>
  
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public IActionResult OnPostExampleHandler([FromForm]ExampleHandlerModel model)
  {
      // ...
  
      return new JsonResult(new { data, message });
  }
  </code></pre>
  
  <p>This is the javascript code which is called on submit:</p>
  
  <pre><code>function submitForm()
  {
      return $.ajax(
          {
              type: "POST",
              url: "/relativeURL/ExampleHandler",
              data: $('#ExampleHandlerForm').serialize(),
              dataType: "json",
  
              complete: function (res)
              {
                  // do something on completion
              }
          });
  }
  </code></pre>
  
  <p>And lastly this is the Html/Razor code, I am using the 'form' TagHelper which ensures the AntiForgeryToken is present when the form is serialized:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form method="post" asp-page-handler="ExampleHandler" id="ExampleHandlerForm"&gt;
  
      &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
              &lt;h5 class="modal-title"&gt;@Model.Details.Description&lt;/h5&gt;
              &lt;button type="button" class="close" data-dismiss="modal"&gt;
                  &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
              &lt;/button&gt;
          &lt;/div&gt;
          &lt;div class="modal-body form-row"&gt;
  
              @* Input Fields *@
  
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
              &lt;button type="button" class="btn btn-secondary" data-dismiss="modal"&gt;@Lang.Operations.Close&lt;/button&gt;
              &lt;button type="button" onclick="submitForm();" class="btn btn-primary"&gt;@Lang.Operations.Save&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <h3>Error Message</h3>
  
  <pre><code>POST http://root:port/relativeURL/ExampleHandler 404 (Not Found)
  send    @   jquery.min.js:2
  ajax    @   jquery.min.js:2
  submitForm  @   VM106:13
  onclick @   5:1
  </code></pre>