我有一个简单的.NET Core 2.0项目。下面是配置方法:当使用UseStatusCodePagesWithReExecute,状态码不会发送到浏览器
public void Configure(IApplicationBuilder app, IHostingEnvironment environment)
{
app.UseStatusCodePagesWithReExecute("/error/{0}.html");
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action?}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
当我输入的网址无效,符合市场预期,显示/error/404.html,但浏览器获得200个状态码,而不是预期的404个状态。
我在做什么错?我可以不使用静态html文件作为错误页面吗?
UseStaticFiles可能会在服务于404.html时设置200。你可以在选项中覆盖它。 – Tratcher