的Enforcing SSL in a ASP.NET Core App指南MSDN,告訴我下面的代碼添加到我的Configure
方法在Startup
類,以重定向所有http
請求https
:AddRedirectToHttps()不重定向到HTTPS
var options = new RewriteOptions()
.AddRedirectToHttps();
app.UseRewriter(options);
已經添加在正確的位置的代碼和測試在調試模式下的HTTP請求,我得到一個connection reset
錯誤鉻:
This site can’t be reached
The connection was reset.
Try:
Checking the connection
Checking the proxy and the firewall
Running Windows Network Diagnostics
ERR_CONNECTION_RESET
我試圖訪問相同的URL(包括端口。 。我認爲哪裏可能會出錯?)如果我使用https ... I.E,我會在地址欄中輸入http://localhost:44376
而不是https://localhost:44376
。
我Configuration
方法的削減版本是這樣的:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
var options = new RewriteOptions()
.AddRedirectToHttps();
app.UseRewriter(options);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentity();
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["Authentication_FacebookAppId"],
AppSecret = Configuration["Authentication_FacebookAppSecret"]
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}