Deploy ASP.NET Core Docker project - get a 405 error (locally in my IIS, web requests works). How to fix it? Deploy ASP.NET Core Docker project - get a 405 error (locally in my IIS, web requests works). How to fix it? heroku heroku

Deploy ASP.NET Core Docker project - get a 405 error (locally in my IIS, web requests works). How to fix it?


The error code 405 means "Method not allowed". The request is being blocked by the server.

First of all, I would analyze if the issue is really on the hosting side (heroku) or in your docker configuration.

The fact that your application runs in IIS on your local machine is an important prerequisite, but doesn't mean it will also run in docker.So I would continue with your docker file: Before you deploy it to your hoster (heroku), run the docker image locally.

One way is to enable it in Visual Studio for your project, another way is to use the command line:

docker container run --name [container_name] [docker_image]

Once it is running, check the port mapping via

docker ps

Then, try to access it via
http://localhost:<add your port>/<add your path here>
or, if you're using SSL/TLS
https://localhost:<add your port>/<add your path here>

If you find that you're getting a 405, you can proceed further:

Check the configuration of your web server inside the docker container, does it allow the required HTTP verbs (GET, PUT, POST, DELETE)? Those are required in a RESTful API. In your example, you're just using GET - so check for this one.

Also check, if any CORS settings are missing. That can also block the requests.

It is also worth reading Microsoft's documents about Containerized Apps to understand how Visual Studio is creating the container for your app. Make sure you read the section about SSL-enabled ASP.NET Core apps describing the settings for Kestrel (the web server you're using in the ASP.NET Core world).

If you found your docker is running fine locally, continue on the hosting side:

Are there any firewall settings blocking your requests? Check the firewall rules of your hoster "heroku" too.If you're using SSL/TLS, then you need to provide a certificate - as described in the link above.

Cited from the link above:

"ASP.NET Core looks for a certificate that matches the assembly name under the Https folder, which is why it is mapped to the container in that path.
The certificate path and password can alternatively be defined using environment variables (that is, ASPNETCORE_Kestrel__Certificates__Default__Path and ASPNETCORE_Kestrel__Certificates__Default__Password)
or in the user secrets json file"