404自定义重定向

use*_*502 5 c# asp.net redirect http-status-code-404

您好我正在尝试重定向,如果响应是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);
        } 

}
Run Code Online (Sandbox Code Playgroud)

UPDATE

到目前为止尝试过

(Response.Status == "404 Not Found")
(Response.Status == "404")
(Response.StatusCode == 404)
Run Code Online (Sandbox Code Playgroud)

SHu*_*Hug 8

您还可以使用web.config customerrors部分 - 如此处所示

例如,在system.web部分,

<customErrors mode="On" defaultRedirect="/custom_error.aspx">
    <error statusCode="404" redirect="/custom_notfound.aspx" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)