title: 405 method not allowed - ASP.NET Web API
body: <p>I have checked all the answers on Google and StackOverflow for 405 method not allowed in ASP.NET Web API and none of the solutions is working.</p>
  
  <ol>
  <li>Checked CORS</li>
  <li>Checked WebDAV</li>
  <li>Checked for HTTPDelete Attribute</li>
  </ol>
  
  <p>I am creating an ASP.NET Web API and have 2 dummy controllers.</p>
  
  <p>I am able to use HTTP Delete method for one controller and not the other controller.</p>
  
  <p><strong>Value Controller</strong></p>
  
  <pre><code>using System.Collections.Generic;
  using System.Web.Http;
  
  namespace JobSite_WebAPI.Controllers
  {
    public class ValuesController : ApiController
    {
      List&lt;string&gt; strings = new List&lt;string&gt;()
      {
          "value1", "value2","value3"
      };
      // GET api/values
      public IEnumerable&lt;string&gt; Get()
      {
          return  strings;
      }
  
      // GET api/values/5
      public string Get(int id)
      {
          return strings[id];
      }
  
      // DELETE api/values/5
      public void Delete(int id)
      {
          strings.RemoveAt(id);
      }
    }
  }
  </code></pre>
  
  <p><strong>Job Details Controller</strong></p>
  
  <pre><code> using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Net;
   using System.Net.Http;
   using System.Web.Http;
   using DataAccess;
  
   namespace JobSite_WebAPI.Controllers
   {
    public class JobDetailController : ApiController
    {
      public JobDetailController()
      {
          JobSiteEntities entities = new JobSiteEntities();
          entities.Configuration.ProxyCreationEnabled = false;
      }
      public IEnumerable&lt;JobDetail&gt;Get()
      {
          using (JobSiteEntities entities = new JobSiteEntities())
          {
              return entities.JobDetails.ToList();
          }
      }
  
  [HttpGet]
      public HttpResponseMessage Get(int id)
      {
          using (JobSiteEntities entities = new JobSiteEntities())
          {
              var entity = entities.JobDetails.FirstOrDefault(e =&gt; e.JOBID == id);
              if (entity != null)
              {
                  return Request.CreateResponse(HttpStatusCode.OK, entity);
              }
              else
              {
                  return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Job With Id = " + id.ToString() + " not found");
              }
          }
      }
  
  
   [HttpGet]
      public HttpResponseMessage RetrieveJobByLocation(string locationName)
      {
          try
          {
              using (JobSiteEntities entities = new JobSiteEntities())
              {
                  IEnumerable&lt;JobDetail&gt; jobDetails = entities.JobDetails.Where(e =&gt; e.Location.LocationName.ToLower() == locationName).ToList();
  
                  if (jobDetails != null)
                      return Request.CreateResponse(HttpStatusCode.OK, jobDetails);
                  else
                      return Request.CreateResponse(HttpStatusCode.NotFound);
  
              }
          }
          catch(Exception ex)
          {
              return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
          }
      }
  
      [HttpDelete]
      public HttpResponseMessage Delete(int jobId)
      {
          try
          {
              using (JobSiteEntities entities = new JobSiteEntities())
              {
                  var entity = entities.JobDetails.FirstOrDefault(e =&gt; e.JOBID == jobId);
  
                  if (entity == null)
                  {
                      return Request.CreateResponse(HttpStatusCode.NotFound, "Job Id with id " + jobId + "is not found");
                  }
                  else
                  {
                      entities.JobDetails.Remove(entity);
                      entities.SaveChanges();
                      return Request.CreateResponse(HttpStatusCode.OK);
                  }
              }
          }
          catch (Exception ex)
          {
              return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
          }
      }
  }
  
  }
  </code></pre>
  
  <p><strong>WebAPIConfig.cs</strong></p>
  
  <pre><code> var cors = new EnableCorsAttribute("*", "*", "*");
   config.EnableCors(cors);
  
  
   // Web API routes
   config.MapHttpAttributeRoutes();
  
   config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
  
          );
          config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/octet-stream"));
  </code></pre>
  
  <p><strong>Web.Config</strong> </p>
  
  <pre><code> &lt;remove name="WebDAV" /&gt;
    &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt;
    &lt;remove name="OPTIONSVerbHandler" /&gt;
    &lt;remove name="TRACEVerbHandler" /&gt;
    &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt;
  </code></pre>
  
  <p>I have enabled CORS,disabled WebDAV.also added HTTPDelete attribute to my delete methods.</p>
  
  <p>The issue am facing is for Value Controller Delete method works fine from Fiddler but for JobDetails Controller i get a 405 method not allowed.</p>
  
  <p>I am able to do a GET and POST Method.Am facing the same issue with PUT too.</p>
  
  <p><strong>Added error message screenshots from fiddler.</strong>
  <a href="https://i.stack.imgur.com/VybeP.png" rel="noreferrer">Fiddler URL</a>
  <a href="https://i.stack.imgur.com/fmewJ.png" rel="noreferrer">Fiddler Error Message</a></p>