Remove Requirement for HTTPS - ASPNet Razor App

Viewed 54

Seems like strange thing to ask:

I am new to the world of .NET & C# and finding myself working on a Razor/Blazor project for a web app.

As part of my learning, I have been going through existing code and reading into various pieces to understand what is going on and I have managed to get through a lot.

One area I am now having issues with is Dockerizing my .NET WebApp.

To be clear - I've been able to Dockerize with no issue in terms of building an Image and running a container but where I am having issues now is it seems like the Web app is configured to only allow access to pages considered AuthorizedAccess when coming from an HTTPS connection.

If I turn off HTTPS redirect etc and login I get to the the Component which says "Sorry You're not authorized to reach this page.". If I do the exact same thing but on the HTTPS port for the app, everything works as expected.

As I will be deploying this container to AWS Fargate and using an ALB + AWS Certificate to fulfil my HTTPS needs, I am stuck with how to essentially turn off whatever is preventing HTTP access. My ALB would be responsible for HTTPS termination so I'm not looking to go sans-https!

Some code I feel is relevant is below:

//Statup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts(); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            }

            // app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }
0 Answers
Related