In ASP.NET Core-6 application, I have this code for PUT Request:
Service:
public Response<object> AppendStatus(string acctNumber, string appendName)
{
var response = new Response<object>();
try
{
using (AseConnection con = new AseConnection(aseConnection))
{
AseCommand cmd = new AseCommand("sp_append", con);
cmd.CommandType = CommandType.StoredProcedure;
var managerId = CodeUsername.Username;
cmd.Parameters.AddWithValue("@AggregatorId", managerId);
cmd.Parameters.AddWithValue("@AcctNo", acctNumber);
cmd.Parameters.AddWithValue("@ManagerName", appendName);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
response.Success = true;
}
catch (Exception ex)
{
_logger.Error($"An Error occured " ex.ToString());
response.Success = false;
}
return response;
}
Then I have this controller:
BaseController:
[Produces("application/json")]
[ApiController]
public class BaseApiController : ControllerBase
{
}
[Consumes("application/json")]
[Authorize]
[Route("api/v1/[controller]")]
public class ManagerController : BaseApiController
{
private readonly ILogger<ManagerControllerr> _logger;
private IAccountsTransService _accountsTransService;
public ManagerController(
ILogger<ManagerController> logger,
IAccountsTransService accountsTransService
)
{
_logger = logger;
_accountsTransService = accountsTransService; }
[HttpPut]
[Route("account/append")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult<Response<object>> AppendAccount(string acctNumber, string appendName)
{
var result = _accountsTransService.AppendAccount(acctNumber, appendName);
return result;
}
The application is deployed on IIS.
When user submits, the error comes up:
Response body:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>405 - HTTP verb used to access this page is not allowed.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div ><fieldset>
<h2>405 - HTTP verb used to access this page is not allowed.</h2>
<h3>The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.</h3>
</fieldset></div>
</div>
</body>
Response headers:
allow: GET,HEAD,OPTIONS,TRACE
content-length: 1293
content-type: text/html
date: Wed,12 Oct 2022 17:15:02 GMT
server: Microsoft-IIS/10.0
x-powered-by: ASP.NET
But this is not affecting GET Request.
As I stated, it is a PUT Request.
How do I resolve it?
CodePudding user response:
Often this error is caused by the WebDAV module that try to handle this kind of requests, an easy solution is to remove WebDAV from your system. You can easily get this done in "Turn Windows Features On or Off" simply un-ticking the checkbox.
If this solution does not solve your problem, you can try the solution in this link:
HTTP Error 405.0 when you visit a website that is hosted on a server that is running IIS.