New answers tagged


My final code after all of the optimization: using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; namespace Website.Middlewares { public class WwwRedirectionMiddleware { ...


If you add IWebHostEnvironment as a dependency to the middleware class, you can simplify the environment check by this: if (webHostEnvironment.IsDevelopment()) { }


Quick remarks: _https_port: do not use underscores in variable names etc., except at the start. _https_port = 80; The HTTPS port is most definitely not port 80. The logic to fill redirectUrl and then redirect is duplicated. It should be a method that gets called. I'd move the "compile new host value in these specific cases" logic to a method and ...

Top 50 recent answers are included