简体   繁体   中英

Listening on HTTP and HTTPS? - C#/ASP.NET/Kestrel

Question - I need my app to force HTTPS connection (443) but if a connection request comes in on 80, to take it and accept it, though on my below code I am getting

IApplicationBuilder does not contain a definition for UseHttpRedirection" and no accessible extension method 'UseHttpRedirection' accepting first argument of type IA ApplicationBuilder could be found, and error HttpRequest does not contain a definition for port.

What am I doing wrong?

        // Always require HTTPS
        app.UseHttpsRedirection();
        //Use when requiring port 80
        app.UseWhen(context => context.Request.Port == 80, httpApp =>
        {
            httpApp.UseHttpRedirection();
        });

Well, there is no method UseHttpRedirection . The only provided redirect is from http to http s

What am I doing wrong?

You can include the https redirect, that's fine. If you bind the server to port 80, that could also work with https. If you find that the middleware does not suit your use case, look into it and copy it: https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/HttpsPolicy/src/HttpsRedirectionMiddleware.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM