title: Simple POST with ASP.NET Framework
body: <p>Here is my problem, I want to receive the Username and Password of the client with <code>POST</code> request.</p>
  
  <p>The code seems simple but doesn't work</p>
  
  <p>The <code>LoginController.cs</code> :</p>
  
  <pre><code>public class LoginController : ApiController
  {
      [HttpPost]
      [ActionName("Login")]
      [Route("api/{controller}")]
      public HttpResponseMessage Login([FromBody] LoginJson json)
      {
          return Request.CreateResponse(HttpStatusCode.OK);
      }
  }
  </code></pre>
  
  <p>The <code>LoginJson.cs</code> form :</p>
  
  <pre><code>public class LoginJson
  {
      public string Username { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>The <code>ajax</code> request with <code>jQuery</code>, i don't want to change the url because i want to use 3 urls <code>/api/Login</code>, <code>/api/Method1</code> and <code>/api/Method2</code> for 3 different controllers:</p>
  
  <pre><code>$.ajax({
          url: '/api/Login',
          type: 'POST',
          dataType: "json",
          contentType: "application/json, charset=utf-8",
          data: JSON.stringify({
              Username: username,
              Password: password,
          }),
          ...
  });
  </code></pre>
  
  <p>The route for API, in <code>Global.asax.cs</code> :</p>
  
  <pre><code>protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
      GlobalFilters.Filters.Add(new HandleErrorAttribute());
      RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
      RouteTable.Routes.MapRoute(...)
  
  
      GlobalConfiguration.Configuration.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{action}",
          defaults: new {action = RouteParameter.Optional}
      );
  }
  </code></pre>
  
  <p>I get error <code>404 (Not Found)</code>.
  I will change the <code>Global.asax.cs</code> file.</p>