我添加了以下代码以在.NetCore2.0中进行安全的https实现。 Https安全通信有效,但是HTTP到https重定向无效。
通过http进行通信时,响应状态为“ err_empty_response”
例如:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
var options = new RewriteOptions()
.AddRedirectToHttps(302, 44358);
app.UseRewriter(options);
app.UseStaticFiles();
app.UseMvc();
}
}