3

Starting point here is a standard template from Microsoft for ASP.NET Core: I used Visual Studio => New Project => .NET Core => ASP.NET Core Web Application

I then ticked the box for HTTPS support and configured Work or School account authentication against an existing Azure AD instance.

Then no matter whether I use http or https to run it locally, the redirect url during authentication always points to https - which is exactly as it should be.

When I deploy this into regular Azure App Service, it has the same behavior, which is fine.

BUT: If I create a docker image from this and deploy it to an Azure AppService with container support (linux-based in this case), then the authentication redirect always goes against http, which is really not what I want.

For reference, this is the Dockerfile used to build the image:

FROM microsoft/dotnet:2.1-sdk AS build

WORKDIR /src
COPY HttpsTest/HttpsTest.csproj HttpsTest/

RUN dotnet restore HttpsTest/HttpsTest.csproj
COPY . .
WORKDIR /src/HttpsTest
RUN dotnet build HttpsTest.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish HttpsTest.csproj -c Release -o /app

FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "HttpsTest.dll"]

Please note that I am not fiddling around with custom certificates inside the container, as I am using Azure App Service to terminate the SSL connection (and bring its own certificate with it along the way).

I am pretty sure there is something I am overlooking here.

Masterfu
  • 1,191
  • 3
  • 14
  • 26

1 Answers1

5

Take a look at Configure ASP.NET Core to work with proxy servers and load balancers, the discussed configuration might help you solve the HTTP redirect issue.

Hope it helps!

Itay Podhajcer
  • 2,616
  • 2
  • 9
  • 14
  • 1
    Thanks for pointing me that way. I got it working by setting the scheme manually: `app.Use((context, next) => { context.Request.Scheme = "https"; return next(); });` – Masterfu Nov 19 '18 at 13:11
  • 1
    Could you please explain the exact cause why it is working after adding the above line as mentioned by @Masterfu. That would be really helpful. – Saurabh Srivastava Feb 26 '20 at 13:10