'Deploy ASP.NET Core Docker project - get a 405 error (locally in my IIS, web requests works). How to fix it?
I am using .net core 3.1. With the help of docker I uploaded my code to heroku. but when i make a web request I get a 405 error with all my endpoints. (I cant see more details of the error)
using Get:
http://xxxx.herokuapp.com/api/pqrs/test/1315315
from visual studio code and also locally from my IIS everything works fine. but the problem occurs when I deploy to my server.
What am I doing wrong? this is the code of my controller:
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using apiPQR.Contexts;
using apiPQR.Entities;
using apiPQR.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
namespace apiPQR.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class Pqrs : Controller
{
private readonly AppDbContext context;
private readonly IConfiguration configuration;
public Pqrs(AppDbContext context, IConfiguration configuration)
{
this.context = context;
this.configuration = configuration;
}
[HttpGet, Route("test/{id}")]
public PQRS Get(int id)
{
var num_pqrs = context.PQRS.FirstOrDefault(p => p.num_solicitud==id);
return num_pqrs;
}
}
}
update:
this is my Dockerfile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["apiPQR.csproj", ""]
RUN dotnet restore "./apiPQR.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "apiPQR.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "apiPQR.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "apiPQR.dll"]
At no time have I seen CORS issues or anything like that. just the 405 error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
