November Happy Hour will be moved to Thursday December 5th.

Custom 404 page in EPi 7 Webforms

Vote:
 

I am having problems setting up a custom 404 page in an EPiServer 7 webforms website.I have a page in the CMS which I use for the 404 page. I have configured my web.config like this:

<system.web>
<customErrors mode="Off" /> 
</system.web>
 
<system.webServer>
<httpErrors existingResponse="Replace" errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="/404" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>

When I navigate to a missing page on the website (i.e http://mysite.local/cheese), two things happen:

  1. A 301 redirect is thrown to a url of 'http://mysite.local/404/?404;http://mysite.local:80/cheese'
  2. A 200 status code is returned for the 404 page.

I expect the 200 status code as this point but am total confused about how the url has been constructed for the 404 (as in why the hostname and port has been added - the original request did not contain a port number)

Anyhow, to turn the 200 status code into a 404, I add the following code to my 404 template:

Response.StatusCode = 404;

Now when I perform a request for http://mysite.local/cheese I get stuck in a redirection loop:

Request 1: http://mysite.local/cheese
R2: http://mysite.local/404/?404;http://mysite.local:80/cheese
R3: http://mysite.local/404/?404;http://mysite.local:80/404/?404;http://mysite.local:80/cheese
R4: http://mysite.local/404/?404;http://mysite.local:80/404/?404;http://mysite.local:80/404/?404;http://mysite.local:80/cheese

I have used this method for 404 pages many times on previous EPi 6 R2 sites. The only difference now is that I am using EPiServer 7 (Patch 3) and .NET 4.5.

I can see a similar thread exists for EPi7 MVC sites where a custom controller and route is required. Do I need to-do the same for a webforms project and if so can anybody help with how?

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=67838

Many thanks,

Adam

#72185
Jun 10, 2013 17:07
Vote:
 

I usually go with this setup for a 404:

<configuration>
  <system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404"
              subStatusCode="-1" />
      <error statusCode="404"
             prefixLanguageFilePath=""
             path="/404/"
             responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>
</configuration>

Plus having an ordinary EPiServer Page with the path /404/.

Remember to add HTTP Errors as Feature to your IIS. It's usually found among "Common HTTP Features".

With HTTP Errors installed you can also use the IIS Manager to tweak your settings and it'll save to your web.config.

I hope it's a push in the right direction.

/Alf

#72189
Jun 10, 2013 20:41
Vote:
 

Thanks Alf - Thats it!

The trailing forward slash on the end of the 404 url was the problem, without it, a redirection loop occurs.

A bit strange as this was not the case in EPi 6. It seems in EPi 7, all urls end with a forward slash.

 

#72202
Jun 11, 2013 9:46
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.