Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Fixes for root node resolution in a multi site context #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Models/UrlTrackerDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public string UrlWithDomain
{
/*var url = new Node(node.Id).Url;
return url;*/
return Node.Url; // do not re-instantiate
var url = !Node.Url.StartsWith("/")
? Node.Url
: string.Format("{0}{1}{2}", Uri.UriSchemeHttp, Uri.SchemeDelimiter, HttpContext.Current.Request.Url.Host) + Node.Url;
return url.TrimEnd('/'); // do not re-instantiate
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion Repositories/UrlTrackerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using InfoCaster.Umbraco.UrlTracker.Extensions;
using InfoCaster.Umbraco.UrlTracker.Helpers;
using InfoCaster.Umbraco.UrlTracker.Models;
Expand Down Expand Up @@ -52,7 +53,10 @@ public static bool AddUrlMapping(IContent content, int rootNodeId, string url, A
if (UrlTrackerSettings.HasDomainOnChildNode)
{
var rootNode = new Node(rootNodeId);
var rootUri = new Uri(rootNode.NiceUrl);
var rootUrl = !rootNode.Url.StartsWith("/")
? rootNode.NiceUrl
: string.Format("{0}{1}{2}", Uri.UriSchemeHttp, Uri.SchemeDelimiter, HttpContext.Current.Request.Url.Host) + rootNode.NiceUrl;
var rootUri = new Uri(rootUrl);
var shortRootUrl = UrlTrackerHelper.ResolveShortestUrl(rootUri.AbsolutePath);
if (url.StartsWith(shortRootUrl, StringComparison.OrdinalIgnoreCase))
{
Expand Down
25 changes: 2 additions & 23 deletions UrlTrackerApplicationEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
using InfoCaster.Umbraco.UrlTracker.Models;
using InfoCaster.Umbraco.UrlTracker.Repositories;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.web;
using umbraco.DataLayer;
using umbraco.NodeFactory;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
using Umbraco.Web.Cache;
using Umbraco.Web.UI.Pages;

namespace InfoCaster.Umbraco.UrlTracker
Expand Down Expand Up @@ -48,9 +44,7 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
ContentService.Publishing += ContentService_Publishing;
ContentService.Deleting += ContentService_Deleting;
content.BeforeClearDocumentCache += content_BeforeClearDocumentCache;
Domain.AfterDelete += Domain_AfterDelete;
Domain.AfterSave += Domain_AfterSave;
Domain.New += Domain_New;
DomainCacheRefresher.CacheUpdated += (s, e) => UmbracoHelper.ClearDomains();
}
}

Expand Down Expand Up @@ -176,20 +170,5 @@ void content_BeforeClearDocumentCache(Document doc, DocumentCacheEventArgs e)
}
#endif
}

void Domain_New(Domain sender, NewEventArgs e)
{
UmbracoHelper.ClearDomains();
}

void Domain_AfterSave(Domain sender, SaveEventArgs e)
{
UmbracoHelper.ClearDomains();
}

void Domain_AfterDelete(Domain sender, umbraco.cms.businesslogic.DeleteEventArgs e)
{
UmbracoHelper.ClearDomains();
}
}
}