Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 Custom Redirect

Hello I am trying to do a redirect if the response is a 404 but it is not working as expected, can you experts see the issue?. It still goes to the generic 404

in my Global.asax

protected void Application_BeginRequest(Object sender, EventArgs e)
{
       if (Response.Status == "404 Not Found")
        {
            string notFound = "~/custom_notfound.aspx";
            Response.Redirect(notFound);
        } 

}

UPDATE

Tried so far

(Response.Status == "404 Not Found")
(Response.Status == "404")
(Response.StatusCode == 404)
like image 879
user710502 Avatar asked Oct 04 '11 18:10

user710502


1 Answers

You can also use the web.config customerrors section - as shown here

e.g. In the system.web section,

<customErrors mode="On" defaultRedirect="/custom_error.aspx">
    <error statusCode="404" redirect="/custom_notfound.aspx" />
</customErrors>
like image 102
SHug Avatar answered Oct 10 '22 04:10

SHug