I'm trying to deploy the Asp.net Web API template in an azure container app. The deploy finish with successful but when i navigate the Url it return 404 error.
I've enabled External traffic but still not working, missing something?
It tell that it only work if in enviroment the property internal is set to false. But i can't find that property
I created a ASP.NET Core Web API
VS template and Deployed to Container apps.
This is my project structure:
Default Dockerfile
:
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "./WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
This is my configuration of the Container App.
OUTPUT
:It is throwing 404 error on the Url because API is not hosted on the home('/')
path.
API is hosted on path /weatherforecast
.
To add swagger you need to add these code in you Program.cs
swagger.SwaggerEndpoint("/swagger/v1/swagger.json", "Web API 1");
it will generate a swagger file based on the router/contoller/model used in project to render the swagger UI when web API is build.
app.Environment.IsProduction()
is added for production environment like Azure or any other cloud services.
if (app.Environment.IsDevelopment()|| app.Environment.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI(swagger =>
{
swagger.SwaggerEndpoint("/swagger/v1/swagger.json", "Web API 1");
});
}
It is accessible at path /swagger/index.html