I have been trying to have my web app to redirect to a custom 404 page. It works for all urls except if they have a ".aspx" extension
The server is a Windows Server 2008 and here are the following settings I have in my web.config (using google.com as a quick example):
<customErrors defaultRedirect="http://www.google.com" mode="On" redirectMode="ResponseRedirect"></customErrors>
<httpErrors errorMode="Custom">
<clear />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404-Page/" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/404-Page/" responseMode="ExecuteURL" />
</httpErrors>
Again the HTTP Errors work for everything but extensions of ".aspx"
The customErrors element provides information about custom error messages for an ASP.NET application. Try adding a error child element to the customErrors element for the specific HTTP error code you want to trap.
<error statusCode="404" redirect="error404.htm"/>
I had a similar problem in IIS6. I ended up handling it in Application_Error in global.asax. To make it work I had to set the 404 custom page to an aspx page that didn't exist (if I set it to an existing aspx page it would get swallowed up by EPiServer's internal error handling...)
Well to solve this issue, we ended up having to create a module that hijacks any errors and transfers the user to my custom 404 page that is set in the web.config (under customErrors). The module would add an event handler to whenever the application gets an error:
public void Init(HttpApplication context)
{
context.Error += new EventHandler(FileNotFound_Error);
}
And the function FileNoteFound_Error does the redirection.
Related
Default error pages may expose a lot of information, Like the language and the server you use, and such Info. could be used by malicious users to attack your site and your server.
Also default error pages look very ugly and outdated design, which may harm your brand.
So It's always recommended to use custom error pages..
So, How Could I display a custom error page in DNN when error occurs ?
1.To Disable DNN Error Handling, and Let Errors Bubble..
Host Settings >> Appearance >> Un-Check "Use Custom Error Messages? "
2.To Redirect Users To, Can be aspx page, but I prefer HTML
Then Create HTML Page at the root with Style
3.in Enable CustomErrors in Web.Config :
<customErrors mode="On">
<error statusCode="500" redirect="/MyCustomError.html"/>
<error statusCode="404" redirect="/MyCustomError.html"/>
<error statusCode="403" redirect="/MyCustomError.html"/>
</customErrors>
Also You can Override IIS Error Pages and Redirect to your Custom Error Pages using the below web.config snippet
<httpErrors>
<remove statusCode="404" subStatusCode="-1"/>
<error statusCode="404" prefixLanguageFilePath="" path="/MyCustomError.aspx" responseMode="ExecuteURL"/>
<remove statusCode="403" subStatusCode="-1"/>
<error statusCode="403" prefixLanguageFilePath="" path="/MyCustomError.html" responseMode="ExecuteURL"/>
</httpErrors>
I have EPiServer application which sometimes might throw exception on application start when loading some configuration or exception occurs in EPiServer initialization pipeline. I have configured customErrors to redirect to /Error.htm page and I am handling this page's response status code in Application_EndRequest event in global.asax to return correct status code like this:
protected void Application_EndRequest(object sender, EventArgs e)
{
if (Request.Url.AbsolutePath.EndsWith("Error.htm"))
{
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;
}
}
It works great when exceptions occur when application is loaded, but not when loading config file (episerver.config in my case) or exception occurs in EPiServer initialization pipeline (there is one bug in EPiServer).
Tried to create IHttpModule, but it is not initialized. Tried to add error handling in Application_Error, but it is not fired too.
It seems that ASP.NET is handling these exceptions because it redirects to my Error.htm page correctly, but it sets status code 304. And I cannot find a way to get into pipeline to change the status code.
I need 500 status code for error page to configure load balancer to take off misconfigured server.
UPDATE
I have set custom errors Off so that correct status code is sent to IIS:
<customErrors mode="Off" defaultRedirect="/Error.htm"></customErrors>
Configured httpError section to redirect to Error.htm, but full exception details are shown locally and remotely. When I add existingResponse="Replace" it throws exception because of loop of redirects:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath="" path="Error.htm" responseMode="Redirect" />
</httpErrors>
Configured httpError section to ExecuteURL, but still full exception details are shown locally and remotely. When I add existingResponse="Replace" it still shows full exception details locally and remotely:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath="" path="/Error.htm" responseMode="ExecuteURL" />
</httpErrors>
If I set responseMode="File" and existingResponse="Replace" it shows Error.htm locally and remotely:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" prefixLanguageFilePath="" path="Error.htm" responseMode="File" />
</httpErrors>
Still no luck to get error details locally and Error.htm remotely.
In EPiServer 7 and up you can use globalErrorHandling to set the expected behavior.
To get the error handling done by httpErrors/customErrors you can set the parameter to Off:
<episerver>
<applicationSettings globalErrorHandling="Off" />
</episerver>
Possible values are "RemoteOnly|On|Off" as documented here: http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/8/Configuration/Configuring-episerver/
You can access this parameter in the back office as well (which is going to edit your web.config on save):
You could probably look into <httpErrors> as opposed to <customErrors>?
Some info at http://tedgustaf.com/blog/2011/5/custom-404-and-error-pages-for-asp-net-and-static-files/.
You might need to disable the EPiServer error handling. You do that by opening your episerver.config and setting the "globalErrorHandling" attribute on the "" element to "Off".
With globalErrorHandling on, my customErrors and httpErrors settings would not work as expected.
Part of the answer was copied from this address: http://www.eyecatch.no/blog/2011/09/custom-error-pages-in-episerver/
We're migrating an existing website from IIS6 to IIS7, but are experiencing some difficulty in setting up the 404 error page. Our 404-errorpage works like this:
A custom ASP-page checks the URL against a short list of 'special' URLs (e.g. http://example.com/limited-offers).
If the URL is known, it redirects to the actual URL of that page.
Otherwise the visitor is redirected to a static errorpage with a 404-statuscode.
With IIS6 this worked as advertised, but with IIS7 some things have changed. IIS7 will always display the configured errorpage when it encounters a statuscode for which an errorpage is defined. In case of our static errorpage with 404-statuscode, this means that IIS7 will execute the custom ASP-page again. This leads to infinite redirection.
We've discovered that this behavior can be circumvented by adding a setting in Web.Config
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
However, after adding this our custom ASP-page refuses to redirect. After checking with Fiddler it seems that IIS7 forces the 404 statuscode, overwriting our 302 redirect.
Can anyone recommend another approach to solve our problem?
I successfully use a similar setup which I migrated from IIS 6 to IIS 7.
My web.config has the following section;
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/302page.asp" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/500page.asp" responseMode="ExecuteURL" />
<error statusCode="500" subStatusCode="100" path="/500page.asp" responseMode="ExecuteURL" />
</httpErrors>
<system.webServer>
I configured this on the relevant site via IIS Manager but you could do it via web.config file if easier for you.
You can add conditional header depending on whether should be 301, 302 or 404.
404;
Response.Status = "404 Not Found"
Response.AddHeader "Location", pagename
302 (temporary re-direct);
Response.Status="301 Object Moved"
Response.AddHeader "Location", pagename
301 (permanent re-direct);
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", pagename
IIS site's application pool uses Integrated pipeline-mode. And attached are settings for debugging section for site.
I encountered a similar scenario for a client the other week. The solution was to configure your <httpErrors> as follows:
<httpErrors errorMode="Custom" existingResponse="Auto">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404"
prefixLanguageFilePath=""
path="/404.asp"
responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="100" />
<error statusCode="500"
subStatusCode="100"
prefixLanguageFilePath=""
path="/500-100.asp"
responseMode="ExecuteURL" />
</httpErrors>
This works with Cactushop (written in Classic ASP) which has "friendly" urls and where they use the 404 handler page to parse the url and render products or list categories of products and so on.
Alternatively you could look at using the IIS addon module: URLRewrite. This will allow you to set up custom SEO friendly URL's. You might find this something you want to look at to improve your application going forward rather than as a fix for your existing issue as may require some time to learn.
There's some excellent articles, video tutorials and info on how to use this tool.
I've got this in the web.config:
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error/NotFound.aspx" responseMode="Redirect" />
<error statusCode="500" prefixLanguageFilePath="" path="/Error/ServerError.aspx" responseMode="Redirect" />
</httpErrors>
But IIS still shows the built in error page.
Any ideas?
You may also need to set the existingReponse attribute in the httpErrors element like this:
<httpErrors errorMode="Custom" existingResponse="Replace">
<clear />
<error statusCode="404" prefixLanguageFilePath="" path="/ErrorHandler.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/ErrorHandler.aspx" responseMode="ExecuteURL" />
</httpErrors>
This is how I am using it and it works to me, it looks pretty similar except for the subStatusCode directives and the ExecuteURL.
<httpErrors>
<!--Remove inherited 500 error page setting -->
<remove statusCode='500' subStatusCode='-1'/>
<!--Override the inherited 500 error page setting with the 'My500.html' as its path-->
<error statusCode='500' subStatusCode='-1' prefixLanguageFilePath='' path='/My500.html' responseMode='ExecuteURL'/>
</httpErrors>
If you are using ExecuteURL, the custom error page path must be in the same application pool as the application itself.
For architectural reasons, IIS 7.0 can only execute the URL if it is located in the same Application Pool. Use the redirect feature to execute a Custom Error in a different Application Pool.
It seems as though you are using a server relative URL, try setting responseMode="ExecuteURL", from MSDN.
ExecuteURL
Serves dynamic content (for example,
an .asp file) specified in the path
attribute for the custom error. If
responseMode is set to ExecuteURL, the
path value has to be a server relative
URL. The numeric value is 1.
Redirect
Redirects client browsers to a the URL
specified in the path attribute that
contains the custom error file. If
responseMode is set to Redirect, the
path value has to be an absolute URL.
The numeric value is 2.
Ensure that you have the proper feature setting for the Error Page redirection in IIS. To check this, from the Error Pages page in IIS Manager, click Edit Feature Settings and make sure Custom error pages is checked if you are testing the redirects from the web server itself. If you are testing remotely, you can leave Detailed errors for local requests and custom error pages for remote requests is checked. This appears to be the default option in my test environment.
I have set up a page to handle errors that occur in a website I work on using web.config. I have used the customErrors section in web.config to do this, as described here
Here is the relevant section
<customErrors mode="On" defaultRedirect="page.aspx?IDDataTreeMenu=357">
<error statusCode="403" redirect="page.aspx?IDDataTreeMenu=357"/>
<error statusCode="404" redirect="page.aspx?IDDataTreeMenu=357" />
</customErrors>
This seems to work for all errors except 404. I just get the standard IIS 404 error when accessing a URL that doesn't exist.
What am I missing here?
This site is hosted on a shared server, so changing settings in IIS is not an option
Check with the ISP and see if they have a place where you can insert a reference to your own custom 404 page.
At Network Solutions they give you a control panel and a page where you can set this up.
<httpErrors>
<clear />
<error statusCode="404" subStatusCode="-1" path="/404.asp" responseMode="ExecuteURL" />
</httpErrors>