Returning
the 404 Status code

Apr 02

Introduction

Using the custom errors and redirecting 404 requests to a Sitefinity page doesn't set\return the 404 response status. The issue arrives when your 404 page is based on a master page. To get around this you can either create a custom master page and override the render method or a widget which is added to the page.

The code is pretty straight forward. I found it on the Sitefinity docs. Add the widget to the page and you should see the correct response status.

protected override void Render(HtmlTextWriter writer)
{
    if (!this.IsDesignMode())
    {
        base.Render(writer);
        Page.Response.Status = "404 Not Found";
        Page.Response.StatusCode = 404;
    }
}

Personally I would like to see Sitefinity handle 404 and 500 events out of the box with the ability of developers to override\extend the default implementation including raising events via the EventHub.


Darrin Robertson - Sitefinity Developer

Thanks for reading and feel free to comment - Darrin Robertson

If I was really helpful and you would buy me a coffee if you could, yay! You can.


Leave a comment
Load more comments

Make a Comment

recapcha code