I cant seem to fire my handler, I have touched the web.config file so the cache is cleared but still no joy. I have even placed some code in my class to write to a txt file when it gets fired, still no joy. I have added this line of code to my 404handlers.config:
string errorID = new umbraco.presentation.nodeFactory.Node(rootNodeID).GetProperty("NotFoundPage").Value;
if (errorID != "")
{
_redirectID =
int.Parse(errorID);
_succes =
true;
}
}
}
catch
{
_succes =
false;
}
return _succes;
}
publicint redirectID
{
get
{
return _redirectID;
}
}
#endregion
}
}
I have obviously copied my handler DLL to the umbraco bin folder too, please help! BTW I am using this method as the site runs on server 2008 and as u prob know the umbraco 404 handler dont work properly on 2008.
Dean, please include your complete not found handler section, as the sequence is quite important. Handlers are fired in the order in which they're specified, so if another handler is successful, it will never hit the others that are following.
I haven't go the handler section to hand, I did put my handler before the built in umbraco 404 handler, i double checked this as it did cross my mind. if u still insist i can send the handler file later on today
Code seems fine, did run some tests as I was intrigued as to why this shouldn't work... Frankly, I was thinking that I would be able to attach to the chrome process (my browser of choice) and set some breakpoints to verify whether code was hit, but didn't manage to... altho my custom handler did fire nicely. Did get it to create a text file as specified in the code. It must be something else...
- Your output dll is MyCustomHandler.dll, right? You do get the rootNodeId in your text file, right?
- Node that corresponds to the 'rootNodeID' is of a document type that holds the NotFoundPage property (NotFoundPage should be the alias)?
Well this is it, the purpose of creating a text file was to see if my had handler had been fired, it did not create a text file at all. I will attach the debugger to my browser later and see if i hit a breakpoint in my handler... I guess not. Perhaps i need set something in my web.config file or another config file? I will keep u posted, please feel free to fire more suggestions.
try using ?umbDebugShowTrace=true i found out that notfoundhandler also checks for the namespace, so basically I got it working defining the namespace.
Custom NotFoundHandler
Hi,
I seem to have a problem creating my own custom Error handler. I have been following this guide:
http://umbraco.org/documentation/books/not-found-handlers/creating-a-custom-not-found-handler
I cant seem to fire my handler, I have touched the web.config file so the cache is cleared but still no joy. I have even placed some code in my class to write to a txt file when it gets fired, still no joy. I have added this line of code to my 404handlers.config:
<
notFound assembly="MyCustomHandler" type="NotFoundHandler"/>
still no joy.
here is my NotFoundHandler class :
using
System;
using
System.Xml;
using
System.Xml.XPath;
using
System.Web;
using
umbraco;
using
umbraco.cms.businesslogic.web;
using
umbraco.interfaces;
using
System.IO;
namespace
MyCustomHandler
{
public class NotFoundHandler : INotFoundHandler
{
private int _redirectID = -1;
#region
INotFoundHandler Members
public bool CacheUrl
{
get
{
return false;
}
}
public bool Execute(string url)
{
bool _succes = false;
string currentDomain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
int rootNodeID = Domain.GetRootFromDomain(currentDomain);
StreamWriter SW;
SW =
File.CreateText("C:\\inetpub\\wwwroot\\RapportUmbraco\\UmbracoRootnode.txt");
SW.WriteLine(rootNodeID);
SW.Close();
try
{
if (rootNodeID > 0)
{
string errorID = new umbraco.presentation.nodeFactory.Node(rootNodeID).GetProperty("NotFoundPage").Value;
if (errorID != "")
{
_redirectID =
int.Parse(errorID);
_succes =
true;
}
}
}
catch
{
_succes =
false;
}
return _succes;
}
public int redirectID
{
get
{
return _redirectID;
}
}
#endregion
}
}
I have obviously copied my handler DLL to the umbraco bin folder too, please help! BTW I am using this method as the site runs on server 2008 and as u prob know the umbraco 404 handler dont work properly on 2008.
Dean
Dean, please include your complete not found handler section, as the sequence is quite important. Handlers are fired in the order in which they're specified, so if another handler is successful, it will never hit the others that are following.
Hope this helps.
Regards,
/Dirk
I haven't go the handler section to hand, I did put my handler before the built in umbraco 404 handler, i double checked this as it did cross my mind. if u still insist i can send the handler file later on today
Here it is:
<?xml version="1.0" encoding="utf-8" ?>
<NotFoundHandlers>
<notFound assembly="umbraco" type="SearchForAlias" />
<notFound assembly="umbraco" type="SearchForTemplate"/>
<notFound assembly="umbraco" type="SearchForProfile"/>
<notFound assembly="MyCustomHandler" type="NotFoundHandler"/>
<notFound assembly="umbraco" type="handle404"/>
</NotFoundHandlers>
Dean,
Code seems fine, did run some tests as I was intrigued as to why this shouldn't work... Frankly, I was thinking that I would be able to attach to the chrome process (my browser of choice) and set some breakpoints to verify whether code was hit, but didn't manage to... altho my custom handler did fire nicely. Did get it to create a text file as specified in the code. It must be something else...
- Your output dll is MyCustomHandler.dll, right? You do get the rootNodeId in your text file, right?
- Node that corresponds to the 'rootNodeID' is of a document type that holds the NotFoundPage property (NotFoundPage should be the alias)?
Let me know what output you're currently getting.
Cheers,
/Dirk
Well this is it, the purpose of creating a text file was to see if my had handler had been fired, it did not create a text file at all. I will attach the debugger to my browser later and see if i hit a breakpoint in my handler... I guess not. Perhaps i need set something in my web.config file or another config file? I will keep u posted, please feel free to fire more suggestions.
try using ?umbDebugShowTrace=true
i found out that notfoundhandler also checks for the namespace, so basically I got it working defining the namespace.
<?xml version="1.0" encoding="utf-8" ?>
<NotFoundHandlers>
<notFound assembly="umbraco" type="SearchForAlias" />
<notFound assembly="umbraco" type="SearchForTemplate"/>
<notFound assembly="umbraco" type="SearchForProfile"/>
<notFound namespace="AddressBookApp.notfoundhandlers" assembly="AddressBookApp" type="SearchSharedContent"/>
<notFound assembly="umbraco" type="handle404"/>
</NotFoundHandlers>
Hope it helps.
/Julius Bartkus
that was the answer for me Julius, nice one!
i would 'high five' it but not enough karma yet :D
is working on a reply...