Copied to clipboard

Flag this post as spam?

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


  • Paul Lagmark 65 posts 140 karma points
    Sep 11, 2015 @ 07:30
    Paul Lagmark
    0

    Custom error handler not working as intended

    Im trying to create my own custom error 404 handler. I've followed the "how to"-guide here on Our Umbraco but I can't get it to work.

    This is the code I have right now.

    My handlerclass:

    namespace AVWebUmbraco.UmbracoExtensions.Eventhandlers
    {
    public class NotFound : INotFoundHandler
    {
        private int redirectId;
    
        public bool Execute(string url)
        {
            var server = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();
            if (server == "www.mydomain1.com")
            {
                redirectId = 1234; // the id of the 404 and search page from domain1.com
                return true;
            }
            if (server == "www.mydomain2.com")
            {
                redirectId = 5678; // the id of the 404 and search page from domain2.com
                return true;
            }
            return false;
        }
    
        public bool CacheUrl
        {
            get { return false; }
        }
    
        public int redirectID
        {
            get { return redirectID; }
        }
      }
    }
    

    404handlers.config:

    <NotFoundHandlers>
    <notFound assembly="umbraco" type="SearchForAlias" />
    <notFound assembly="umbraco" type="SearchForTemplate"/>
    <notFound assembly="umbraco" type="SearchForProfile"/>
    <notFound assembly="umbraco" type="handle404"/>
    <notFound assembly="AVWebUmbraco" namespace="AVWebUmbraco.UmbracoExtensions.Eventhandlers" type="NotFound" />
    </NotFoundHandlers>
    

    The error I get is:

    enter image description here

  • Paul Lagmark 65 posts 140 karma points
    Sep 14, 2015 @ 07:30
    Paul Lagmark
    0

    Could it have something do with these lines under

    <customErrors mode="Off" />
    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
    <httpRuntime requestValidationMode="2.0" maxRequestLength="10240" enableVersionHeader="false" targetFramework="4.5" />
    
  • Paul Lagmark 65 posts 140 karma points
    Sep 15, 2015 @ 12:40
    Paul Lagmark
    0

    If anyone can help me with this issue I would be very grateful. I only have today to solve it..

  • Comment author was deleted

    Sep 15, 2015 @ 12:46

    Hmm think your notFOund element isn't correct , which version of Umbraco are you running since the INotFOundHandler will be obsolete http://blog.dampee.be/post/2013/11/21/From-the-legacy-INotFoundHandler-to-IContentFinder.aspx

  • Paul Lagmark 65 posts 140 karma points
    Sep 15, 2015 @ 12:47
    Paul Lagmark
    0

    Im using Umbraco 7.2. I will check your link, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft