在本地和服务器中使用HTTP

时间:2017-05-18 16:16:28

标签: asp.net-core

我正在使用HTTPS开发ASP.NET Core项目,所以我在启动时:

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

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

然后在Program class上我有以下内容:

  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();

我正在检查环境是否为开发使用本地证书。

否则它将使用服务器中的证书(在本例中为Azure)。

这适用于本地和Azure。

但是应该这样做吗?

0 个答案:

没有答案