Use HTTP files locally and on the server

I am working on an ASP.NET Core project using HTTPS, so I have at startup:

// In Configure method
RewriteOptions rewriteOptions = new RewriteOptions(); 
rewriteOptions.AddRedirectToHttps();

// In ConfigureServices method
services.AddMvc(x => {
  x.Filters.Add(new RequireHttpsAttribute());
});     

      

Then, in the Program class, I have the following:

  IWebHostBuilder builder = new WebHostBuilder()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseStartup<Startup>();

  builder.UseKestrel(x => { 

    var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");  

    if (env == "Development"))  
      x.UseHttps(@"../../local.pfx", "Password"); 

  });      

  IWebHost host = builder.Build();

  host.Run();

      

I am checking if the environment is development to use a local certificate.

Otherwise, it will use the certificate on the server (Azure in this case).

This works both locally and in Azure.

But should it be done this way?

+3
asp.net-core


source to share


No one has answered this question yet

Check out similar questions:

nine
Deploying a simple ASP.NET Core 2.2 web app to Azure using Web Deploy fails
3
Asp.Net master data protection between web apps doesn't work in Azure
1
Open my main asp.net web app over the internet
1
Dependency injection error in ASP.NET Core RC2
0
ASP.NET Core WebService
0
Why does QueueClient RegisterSessionHandler stop working?
0
Combining asp.net core and asp.net config
0
Authorize attribute not redirecting to login page when using .NET Core 2 AddJwtBearer
0
How to display debug level log messages in Application Insights in production
0
How to dynamically select a connection string based on environment in .Net Core startup?



All Articles
Loading...
X
Show
Funny
Dev
Pics