Closed thanhhn253 closed 2 years ago
Hello, I have same issue. It work only in theses cases.
docker run --rm -it -p 5001:443 -p 5000:80 ^
-e ASPNETCORE_ENVIRONMENT=Development ^
-e ASPNETCORE_URLS="https://+;http://+" ^
-e ASPNETCORE_HTTPS_PORT=5001 ^
-v %APPDATA%\microsoft\UserSecrets\:/root/.microsoft/usersecrets ^
-v %USERPROFILE%\.aspnet\https:/root/.aspnet/https/ ^
myIdentityServer4
I need to use my docker image on Azure. But, I can't find any way to add a certificate to my docker container.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
COPY src ./src
RUN dotnet restore "src/MyIdentityServerHost/MyIdentityServerHost.csproj"
RUN dotnet build "src/MyIdentityServerHost/MyIdentityServerHost.csproj" -c Release --no-restore
FROM build AS publish
RUN dotnet publish "src/MyIdentityServerHost/MyIdentityServerHost.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyIdentityServerHost.dll"]
Hello,
@thanhhn253 I finally found a solution to solve my issue.
In Startup.cs
, I add theses lines:
public void ConfigureServices(IServiceCollection services)
{
_ = services.Configure<ForwardedHeadersOptions>(options => options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto);
}
public void Configure(IApplicationBuilder app)
{
_ = app.UseForwardedHeaders();
_ = app.Use((context, next) =>
{
if (context.Request.Headers.TryGetValue("X-Forwarded-Proto", out StringValues proto))
{
context.Request.Scheme = proto;
}
return next();
});
}
With this code, authentication work inside a docker container.
Wow, I can login now. Thank you very much for sharing the solution.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Steps to reproduct:
Please check