你好,如果响应是 404,我正在尝试进行重定向,但它没有按预期工作,专家们能看到这个问题吗?它仍然是通用的 404
在我的 Global.asax 中
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Response.Status == "404 Not Found")
{
string notFound = "~/custom_notfound.aspx";
Response.Redirect(notFound);
}
}
更新
到目前为止已经尝试过
(Response.Status == "404 Not Found")
(Response.Status == "404")
(Response.StatusCode == 404)
最佳答案
您还可以使用 web.config 的客户错误部分 - as shown here
例如在 system.web 部分,
<customErrors mode="On" defaultRedirect="/custom_error.aspx">
<error statusCode="404" redirect="/custom_notfound.aspx" />
</customErrors>
关于c# - 404自定义重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7652272/