Copied to clipboard

Flag this post as spam?

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


  • J 447 posts 864 karma points
    Apr 12, 2016 @ 09:17
    J
    0

    Two domains question

    I have a single project with two domains.

    Is it possible to have two separate error pages displayed for each domain i.e. if the user comes across an error on site1 then it redirects the user to the site1 error page (404 for example). If they are on site2 and come across an error then it redirects the user to the site 2 error page.

    Can this be done?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 12, 2016 @ 19:06
    Dan Diplo
    0
  • J 447 posts 864 karma points
    Apr 13, 2016 @ 14:14
    J
    0

    Im not sure if im doing something wrong here or not, but downloaded the project from Git (second link you provided). Loaded it up in VS 2013, browsed to the site (http://localhost:1234 is the address in the browser).

    It shows a page with "Front" and two links. Click link takes me to http://awesome.localhost.bjerner.dk/ and click link two, gives me the standard 404 error page

    Page not found
    
    No umbraco document matches the url '/this-is-a-page/'.
    
    This page can be replaced with a custom 404. Check the documentation for "custom 404".
    
    This page is intentionally left ugly ;-)
    

    I tried to get into debug mode and the only time i get into the "FourOhFourContentFinder" class is when i type http://localhost:1234/PageDoesNotExist which then hits the breakpoint in this class. When i look at the variable rootNodeId its always "-1". so it always returns false.

    Have i missed something or not configured something correctly?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 13, 2016 @ 18:27
    Dan Diplo
    0

    Hi. Here's the implementation I use on multi-lingual sites. It looks for the first page it can find that is created using the document type with an alias of "PageNotFound" (you can easily modify to your own needs). Remember to register it in ApplicationStarting event.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Umbraco.Web.Routing;
    
    namespace Diplo.Core
    {
        /// <summary>
        /// Custom 404 "last chance" handler that is used to display 404 page
        /// See http://creativewebspecialist.co.uk/2013/08/07/the-new-way-to-do-a-404-umbraco-handler/
        /// </summary>
        public class FourOhFourFinder : IContentFinder
        {
            /// <summary>
            /// Used to find the correct 404 page when a page cannot be found in Umbraco
            /// </summary>
            /// <param name="contentRequest">The current Umbraco context</param>
            /// <returns>The 404 page</returns>
            public bool TryFindContent(PublishedContentRequest contentRequest)
            {
                //Check request cannot be found
                if (contentRequest.PublishedContent == null)
                {
                    var domain = contentRequest.Domain;
    
                    if (domain != null)
                    {
                        var home = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(domain.RootNodeId);
    
                        if (home != null)
                        {
                            //Get the 404 node
                            var notFoundNode = home.Children.FirstOrDefault(x => x.DocumentTypeAlias == "PageNotFound");
    
                            if (notFoundNode != null)
                            {
                                //Set Response Status to be HTTP 404
                                contentRequest.SetResponseStatus(404, "404 Page Not Found");
    
                                //Set the node to be the not found node
                                contentRequest.PublishedContent = notFoundNode;
                            }
                        }
                    }
                }
    
                //Not sure about this line - copied from Lee K's GIST
                //https://gist.github.com/leekelleher/5966488
                return contentRequest.PublishedContent != null;
            }
        }
    
        // Also need to register the handler in OnApplicationStarting event
        /*
         *   public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                ContentFinderResolver.Current.InsertTypeBefore<ContentFinderByNotFoundHandlers, Diplo.Core.FourOhFourFinder>();
            }
         * 
         */
    
    }
    
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 13, 2016 @ 19:22
    Dan Diplo
    1

    I've whipped up a quick blog post about this on my site which I hope will help:

    http://www.diplo.co.uk/blog/web-development/404-page-finder-for-multi-site-umbraco-installations/

  • J 447 posts 864 karma points
    Apr 14, 2016 @ 09:52
    J
    0

    Thanks. Im using your link provided to try and do this.

    For the startup event i had to change it to below otherwise it was throwing a compile error

    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    

    This allows the TryFindContent method to be hit. When it does domain is always null?

    var domain = contentRequest.Domain;
    

    Do i need any extra configuration?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 14, 2016 @ 11:33
    Dan Diplo
    1

    Strange that Domain is null. I use this on a number of sites, and it works. I wonder... Have you set a Culture and Hostname for your home pages? ie. right click on a site homepage, select Culture and Hostname and then add Domain information. If you are just testing you can use localhost:1234 (where :1234 is your local port number in IIS Express).

  • J 447 posts 864 karma points
    Apr 14, 2016 @ 14:05
    J
    0

    That is empty at present but not for the second site (will test this shortly).... So am i correct in understanding, in order for this to work all home nodes must have a domain set against them in Culture and Hostname?

    Thanks for your help

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 14, 2016 @ 15:28
    Dan Diplo
    100

    I believe every domain needs to be set, yes. The idea is you set the language (culture) for the site at the home page level, and that then works with things like Dictionary for getting localised content.

    The domain part is if you have different domains eg. you could map:

    uk.domain.com to your UK home page and de.domain.com to your German site (for example).

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies