【发布时间】:2020-11-02 15:32:39
【问题描述】:
我正在使用 Razor Pages,NET CORE 3,为了捕获和处理 404 错误,我实现了以下操作:
app.UseStatusCodePages(context =>
{
var request = context.HttpContext.Request;
var response = context.HttpContext.Response;
if (response.StatusCode == (int)HttpStatusCode.NotFound)
{
response.Redirect("./NotFound", false);
}
return Task.CompletedTask;
});
它在这里工作:http://myServer/myApp/nonExistingPage -> http://myServer/myApp/NotFound
在这种情况下显然不起作用:http://myServer/myApp/doesNotExists/nonExistingPage -> http://myServer/myApp/doesNotExists/NotFound
我读到重定向应该是response.Redirect("~/NotFound", false);。有了这个我得到:
http://myServer/myApp/nonExistingPage -> http://myServer/NotFoundhttp://myServer/myApp/doesNotExists/nonExistingPage -> http://myServer/NotFound
我错过了什么还是什么?
【问题讨论】:
标签: redirect root asp.net-core-3.1