Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.netcore PUT method 405 Method Not Allowed

I have a simple model as that has 2 fields and with the following put method, i'm tring to update it in the db. Everymethod including delete works, however put method always returns a 405 error in Postman. (tried WebDAV solutions as well.) What am I missing here?

enter image description here

PUT METHOD:

{
    "MasterId":1,
    "MasterName":"Test"
}

Action

[HttpPut("{id:int}")]
public async Task<IActionResult> PutMaster(int id, Master master)
{
    if (id != master.MasterId)
    {
        return BadRequest();
    }

    //...some code
    return NoContent();
}
like image 944
Sin5k4 Avatar asked May 05 '26 20:05

Sin5k4


2 Answers

If your application is being hosted under IIS, running API in ASP.NET Core, include this line in the Web.Config file

<configuration> 
    <system.webServer>
        <modules>
             <remove name="WebDAVModule" />
        </modules>
    </system.webServer>
</configuration>
like image 149
César Augusto Avatar answered May 08 '26 11:05

César Augusto


If you are using IIS to run your application and have WebDav module, that can be an issue. For some strange reason WebDav does not allow PUT.

I just uninstalled it, and it helped.

like image 26
Ilya Chernomordik Avatar answered May 08 '26 11:05

Ilya Chernomordik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!