New answers tagged http
0
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
{
...
3
If you add IWebHostEnvironment as a dependency to the middleware class, you can simplify the environment check by this:
if (webHostEnvironment.IsDevelopment())
{
}
2
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
Related Tags
http × 392python × 74
java × 59
c# × 57
beginner × 40
javascript × 39
php × 34
server × 33
performance × 30
error-handling × 30
go × 29
json × 28
asynchronous × 25
multithreading × 24
node.js × 24
c++ × 22
python-3.x × 22
url × 20
socket × 18
network-file-transfer × 16
object-oriented × 15
web-scraping × 15
c × 13
ruby × 13
api × 13