1
votes

I'm creating an ASP .Net Core 2.2 Web API, and am implementing a controller action which will be invoked via a POST. However, when I run it in Debug mode in Visual Studio 2017, and I call the endpoint using Postman, I get a 405 Method Not Allowed

I specified that I am doing this in debug mode in VS because I've seen a couple of posts online where people are getting this issue when deploying, and having to remove WebDAV from IIS or adding this:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="false">
    <remove name="WebDAVModule" />
  </modules>
</system.webServer>

to their config.web

However, seeing as I am running from VS, it is using IIS Express, and there is no web.config file.

I haven't yet tried to publish the API, as it's not even working locally on my machine, so it feels wrong to publish something that's broken.

EDIT:

So my controller looks like this:

public class TestController : ControllerBase
{

    public TestController()
    {
    }

    [HttpPost]
    private void Post()
    {
        Console.Write("TEST");
    }
}
1
Where's your code? There's nothing wrong with POST, all sites use it unless they are read-only. Even the tutorials wouldn't work if forms couldn't POST to the server - Panagiotis Kanavos
Besides, ASP.NET Core doesn't use web.config unless it's hosted on IIS. The default servier is Kestrel - Panagiotis Kanavos
That's right, there is no web.config until you publish. That's why I can't even try the suggestion I've seen online about adding those lines to the web.config file. Regarding the code sample, well, there's not much to post...currently I have a controller with just one simple, parameterless action, which has "Console.Write("TEST"); in its body and nothing else. And it has the [HttpPost] decoration. If I change it to a [HttpGet] decoration, and do a GET request from Postman, then it works. - Fabricio Rodriguez
You don't need a web.config during debugging. Even after publishing it doesn't mean you need one. Kestrel doesn't need it. Post the code. - Panagiotis Kanavos
why is your post method private ? - noobed

1 Answers

2
votes

As mentioned by the keen-eyed noobed, my problem was that my controller action was private and not public. Thanks again noobed.