Custom Error Page

Vote:
 

I'm having some issues with the custom error page. I currently have the setup of the following:

<httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace" defaultResponseMode="ExecuteURL">
      <!-- Remove 400 error codes -->
      <remove statusCode="400" subStatusCode="-1" />
      <remove statusCode="401" subStatusCode="-1" />
      <remove statusCode="402" subStatusCode="-1" />
      <remove statusCode="403" subStatusCode="-1" />
      <remove statusCode="404" subStatusCode="-1" />
      <remove statusCode="405" subStatusCode="-1" />
      <remove statusCode="406" subStatusCode="-1" />
      <remove statusCode="407" subStatusCode="-1" />
      <remove statusCode="408" subStatusCode="-1" />
      <remove statusCode="409" subStatusCode="-1" />
      <remove statusCode="410" subStatusCode="-1" />
      <remove statusCode="411" subStatusCode="-1" />
      <remove statusCode="412" subStatusCode="-1" />
      <remove statusCode="413" subStatusCode="-1" />
      <remove statusCode="414" subStatusCode="-1" />
      <remove statusCode="415" subStatusCode="-1" />
      <remove statusCode="416" subStatusCode="-1" />
      <remove statusCode="417" subStatusCode="-1" />
      <remove statusCode="418" subStatusCode="-1" />
      <remove statusCode="420" subStatusCode="-1" />
      <remove statusCode="422" subStatusCode="-1" />
      <remove statusCode="423" subStatusCode="-1" />
      <remove statusCode="424" subStatusCode="-1" />
      <remove statusCode="425" subStatusCode="-1" />
      <remove statusCode="426" subStatusCode="-1" />
      <remove statusCode="428" subStatusCode="-1" />
      <remove statusCode="429" subStatusCode="-1" />
      <remove statusCode="431" subStatusCode="-1" />
      <remove statusCode="444" subStatusCode="-1" />
      <remove statusCode="449" subStatusCode="-1" />
      <remove statusCode="450" subStatusCode="-1" />
      <remove statusCode="451" subStatusCode="-1" />
      <remove statusCode="494" subStatusCode="-1" />
      <remove statusCode="495" subStatusCode="-1" />
      <remove statusCode="496" subStatusCode="-1" />
      <remove statusCode="497" subStatusCode="-1" />
      <remove statusCode="499" subStatusCode="-1" />
      <!-- Remove 500 error codes -->
      <remove statusCode="500" subStatusCode="-1" />
      <remove statusCode="501" subStatusCode="-1" />
      <remove statusCode="502" subStatusCode="-1" />
      <remove statusCode="503" subStatusCode="-1" />
      <remove statusCode="504" subStatusCode="-1" />
      <remove statusCode="505" subStatusCode="-1" />
      <remove statusCode="506" subStatusCode="-1" />
      <remove statusCode="507" subStatusCode="-1" />
      <remove statusCode="508" subStatusCode="-1" />
      <remove statusCode="509" subStatusCode="-1" />
      <remove statusCode="510" subStatusCode="-1" />
      <remove statusCode="511" subStatusCode="-1" />
      <remove statusCode="598" subStatusCode="-1" />
      <remove statusCode="599" subStatusCode="-1" />
      <!-- New 400 error code messages -->
      <error statusCode="400" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="401" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="402" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="403" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="404" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="405" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="406" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="407" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="408" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="409" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="410" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="411" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="412" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="413" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="414" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="415" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="416" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="417" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="418" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="420" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="422" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="423" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="424" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="425" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="426" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="428" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="431" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="444" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="449" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="450" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="494" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="495" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="496" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="497" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="499" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <!-- New 500 error code messages -->
      <error statusCode="500" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="501" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="502" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="503" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="504" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="505" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="506" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="507" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="508" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="509" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="510" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="511" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="512" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="598" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
      <error statusCode="599" prefixLanguageFilePath="" path="/Pages/Error.aspx" />
    </httpErrors>
<customErrors mode="RemoteOnly" defaultRedirect="/Pages/Error.aspx" />

Someone brought up the following point:

Hi!

Here’s an example:
When we try to retrieve a css file that was renamed, we don’t get a 404 anymore, we get the error page.
This means that it’s difficult to notice there was a 404 happening, since the browser doesn’t highlight the error.
Furthermore we get the cost of creating the complete error page when we aren’t accessing a page. We also fill up the log with different object access during the debug sessions with lookup to objects that we don’t expect at that time due to the error page being constructed.
Another example is if we have a publicly available url and we change that url. Then a crawler (say google) comes by and tries to fetch the old url. Then it won’t notice the 404 since it’s removed, but it will think that the url is correct and then it records it’s content, which is the error text. We really don’t want the error text indexed as a proper page in search engines.

I hope this clears out the issues we are having.

I’ve currently changed my web config with the setting existingResponse=”PassTrough”. That makes the css files 404 correctly, but I haven’t analyzed it further.


I thought this was the best way to setup the custom error page. Is there another way to do this because I haven't been able to find an alternate solution?

#62025
Oct 10, 2012 16:00
Vote:
 

Hi,


To catch all errors, this is the simplest way (if you're using IIS7 and above):

<system.web>
		<customErrors defaultRedirect="/Error.aspx" mode="On" redirectMode="ResponseRewrite">
			<error statusCode="404" redirect="/NotFound.aspx" />
			<error statusCode="500" redirect="/Error.aspx" />
		</customErrors>
</system.web>
...
<system.webServer>
		<httpErrors errorMode="Custom">
			<remove statusCode="404" />
			<error statusCode="404" path="/notfound.aspx" responseMode="ExecuteURL" />
			<remove statusCode="500" />
			<error statusCode="500" path="/error.aspx" responseMode="ExecuteURL" />
		</httpErrors>
</system.webServer>

    

#62034
Oct 10, 2012 17:28
Vote:
 

And on your error pages you have to send the correct status codes

if (Request.HttpMethod == "GET")
{
    Response.Status = "404 not found";
    Response.StatusCode = 404;                
}

    And so on...

#62036
Oct 10, 2012 17:30
Vote:
 

So in the customErrors section, do I have to define the error codes there as well as in the httpErrors, or can I get away with defining the error codes only in the httpErrors?

#62038
Oct 10, 2012 18:30
Vote:
 

That's a good question. I guess you need all the 500 error codes in httpErrors at least, but maybe that's overkill. 500 is the most common.

The reason for customErrors is to catch other requests than .aspx, e.g. .htm and directories that doesn't exists.

#62039
Oct 10, 2012 18:39
Vote:
 

And if you want the requested url on your 404 page:

string requestedUrl = Request.QueryString["aspxerrorpath"] ?? Request.RawUrl

    

#62040
Oct 10, 2012 18:43
Vote:
 

Oh nice. Thank you for all your help.

#62041
Oct 10, 2012 19:09
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.