Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dean Beasley 11 posts 34 karma points
    Nov 27, 2009 @ 16:03
    Dean Beasley
    1

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 27, 2009 @ 17:29
    Dirk De Grave
    0

    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

  • Dean Beasley 11 posts 34 karma points
    Nov 27, 2009 @ 19:47
    Dean Beasley
    0

    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

  • Dean Beasley 11 posts 34 karma points
    Nov 27, 2009 @ 19:49
    Dean Beasley
    0

    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>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 28, 2009 @ 17:31
    Dirk De Grave
    0

    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

  • Dean Beasley 11 posts 34 karma points
    Nov 29, 2009 @ 00:43
    Dean Beasley
    0

    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.

  • Julius Bartkus 51 posts 76 karma points
    Dec 07, 2009 @ 11:11
    Julius Bartkus
    1

    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

  • andrew shearer 510 posts 659 karma points
    Sep 16, 2010 @ 02:14
    andrew shearer
    0

    that was the answer for me Julius, nice one!

    i would 'high five' it but not enough karma yet :D

     

Please Sign in or register to post replies

Write your reply to:

Draft