using System.Configuration;
using umbraco.interfaces;
namespace TempNamespace.Web
{
public class LocalizedNotFoundHandler : INotFoundHandler
{
private int redirectId;
public bool Execute(string url)
{
try
{
var errorPage = ConfigurationManager.AppSettings["errorPageId"];
int errorPageId;
if (!int.TryParse(errorPage, out errorPageId))
{
return false;
}
redirectId = errorPageId;
return true;
}
catch
{
return false;
}
}
public bool CacheUrl
{
get { return false; }
}
public int redirectID
{
get { return redirectId; }
}
}
}
The SEOChecker is working just fine, and the umbraco handle404 is working correctly. But my code never works. I've tried to remove SEOChecker and handle404, and still nothing. Between every change, i've been updating the web.config so that the app refreshes.
I ever removed all of my code and just use the generic implementation of INotFoundHandler and still no luck. There went my day, and I know it's a stupid user error too...
2013-04-19 17:43:56,773 [11] WARN Umbraco.Web.Routing.NiceUrlProvider - [Thread 30] Couldn't find any page with nodeId=-1. This is most likely caused by the page not being published.
2013-04-19 17:43:56,774 [11] DEBUG Umbraco.Core.PluginManager - [Thread 30] LookupDocument: End resolvers, no document was found (took 49ms)
Custom 404 Handler never gets called
I created a custom 404 handler for v6.0.2. I followed the information here: http://our.umbraco.org/wiki/how-tos/how-to-implement-your-own-404-handler.
My code for the handler is:
Then I updated the 404handler.config:
The SEOChecker is working just fine, and the umbraco handle404 is working correctly. But my code never works. I've tried to remove SEOChecker and handle404, and still nothing. Between every change, i've been updating the web.config so that the app refreshes.
Ideas?
-C
Hi Chad,
Are you sure that <notFoundassembly="ASSEMBLYNAME"namespace="YOURNAMESPACE"type="HANDLERCLASS"/> you write in right way ?
THanks,
Alex
I just retried it.
No luck.
-C
Type should be full name.
Problem definitely is in this Config.
I ever removed all of my code and just use the generic implementation of INotFoundHandler and still no luck. There went my day, and I know it's a stupid user error too...
-C
Here is my trace, my code never gets called.
2013-04-19 17:43:56,731 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering custom handlers.
2013-04-19 17:43:56,732 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.SearchForAlias,umbraco'.
2013-04-19 17:43:56,734 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.SearchForTemplate,umbraco'.
2013-04-19 17:43:56,734 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.SearchForProfile,umbraco'.
2013-04-19 17:43:56,734 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'SEOChecker.Handlers.NotFoundHandlers.Inbound404Handler,SEOChecker'.
2013-04-19 17:43:56,736 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'TempNamespace.Web.LocalizedNotFoundHandler,TempNamespace.Web'.
2013-04-19 17:43:56,737 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Registering 'umbraco.handle404aaa,umbraco'.
2013-04-19 17:43:56,738 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Running for legacy url='asdf'.
2013-04-19 17:43:56,739 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'umbraco.SearchForAlias'.
2013-04-19 17:43:56,740 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Replace handler 'umbraco.SearchForAlias' by new lookup 'Umbraco.Web.Routing.LookupByAlias'.
2013-04-19 17:43:56,742 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'umbraco.SearchForTemplate'.
2013-04-19 17:43:56,742 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Replace handler 'umbraco.SearchForTemplate' by new lookup 'Umbraco.Web.Routing.LookupByNiceUrlAndTemplate'.
2013-04-19 17:43:56,761 [11] DEBUG Umbraco.Web.Routing.LookupByNiceUrlAndTemplate - [Thread 30] Not a valid template: "asdf"
2013-04-19 17:43:56,761 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'umbraco.SearchForProfile'.
2013-04-19 17:43:56,761 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Replace handler 'umbraco.SearchForProfile' by new lookup 'Umbraco.Web.Routing.LookupByProfile'.
2013-04-19 17:43:56,762 [11] DEBUG Umbraco.Web.Routing.LookupByProfile - [Thread 30] Not the profile path
2013-04-19 17:43:56,762 [11] DEBUG Umbraco.Web.Routing.LookupByNotFoundHandlers - [Thread 30] Handler 'SEOChecker.Handlers.NotFoundHandlers.Inbound404Handler'.
2013-04-19 17:43:56,773 [11] WARN Umbraco.Web.Routing.NiceUrlProvider - [Thread 30] Couldn't find any page with nodeId=-1. This is most likely caused by the page not being published.
2013-04-19 17:43:56,774 [11] DEBUG Umbraco.Core.PluginManager - [Thread 30] LookupDocument: End resolvers, no document was found (took 49ms)
So my issue had nothing to do with the code. Because I have the code in a project, I needed to set the Build Action to 'Compile'. Voila. It now works.
-C
Hi Chad,
I'm having the same issue as the Custom 404 Handler are not being called.
For the <notFound> part which did you used for it to work as below?
a) <notFoundassembly="TempNamespace.Web"type="TempNamespace.Web.LocalizedNotFoundHandler"/>
b) <notFoundassembly="TempNamespace.Web"type="LocalizedNotFoundHandler"/>
c) <notFound assembly="TempNamespace.Web" namespace="TempNamespace.Web" type="LocalizedNotFoundHandler" />
One more thing, inside your UmbracoSettings.config as below.
Do you leave your <error404></error404> empty?
<errors>
<!-- the id of the page that should be shown if the page is not found -->
<!-- <errorPage culture="default">1</errorPage>-->
<!-- <errorPage culture="en-US">200</errorPage>-->
<error404>1088</error404>
</errors>
is working on a reply...