0

In .NET Core 7 Web API, which utilizes Entity Framework, I encountered an error when making HTTP PUT and DELETE requests on the server. However, the code works correctly when running locally.

The specific error received is "405 - HTTP verb used to access this page is not allowed."

APIs:

[HttpDelete]
[Route("DeleteCode")]
[Authorize]
public ActionResult DeleteCode(int Id)
{
}

and

[Route("EditCode")]
[HttpPut]
[Authorize]
public ActionResult EditCode(CodeDTO model)
{
}

Please note that my database is hosted on Plesk.

I tried adding the suggested code to the server's webconfig file, but unfortunately, it did not resolve the issue.

<system.webServer>
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webServer>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

check tow things

1- using System.Web.Mvc; // Wrong namespace for HttpGet attribute !!!!!!!!!

2- using System.Web.Http; // Correct namespace for HttpGet attribute !!!!!!!!!

also routing

config.Routes.MapHttpRoute(
    name: "GetAllRoute",
    routeTemplate: "api/{controller}.{ext}"/*,
    defaults: new { action = "Get" }*/ // this was causing the issue
);

check the routing also.

 <system.webServer> <modules runAllManagedModulesForAllRequests="false"> <remove name="WebDAVModule" /> </modules> </system.webServer>
user123456
  • 2,524
  • 7
  • 30
  • 57