Adds more description to CustomRouteUrlProvider
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// This url provider is used purely to deal with umbraco custom routes that utilize UmbracoVirtualNodeRouteHandler and will return
|
||||
/// This url provider is used purely to deal with umbraco custom routes that utilize <see cref="UmbracoVirtualNodeRouteHandler"/> and will return
|
||||
/// the URL returned from the current PublishedContentRequest.PublishedContent (virtual node) if the request is in fact a virtual route and
|
||||
/// the id that is being requested matches the id of the current PublishedContentRequest.PublishedContent.
|
||||
/// </summary>
|
||||
internal class CustomRouteUrlProvider : IUrlProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// This will simply return the URL that is returned by the assigned IPublishedContent if this is a custom route
|
||||
/// This will return the URL that is returned by the assigned custom <see cref="IPublishedContent"/> if this is a custom route
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <param name="id"></param>
|
||||
@@ -30,7 +32,11 @@ namespace Umbraco.Web.Routing
|
||||
if (umbracoContext.HttpContext.Request.RequestContext.RouteData == null) return null;
|
||||
if (umbracoContext.HttpContext.Request.RequestContext.RouteData.DataTokens == null) return null;
|
||||
if (umbracoContext.HttpContext.Request.RequestContext.RouteData.DataTokens.ContainsKey(Umbraco.Core.Constants.Web.CustomRouteDataToken) == false) return null;
|
||||
//ok so it's a custom route with published content assigned, check if the id being requested for is the same id as the assigned published content
|
||||
|
||||
//If we get this far, it means it's a custom route with published content assigned, check if the id being requested for is the same id as the assigned published content
|
||||
//NOTE: This looks like it might cause an infinite loop because PublishedContentBase.Url calls into UmbracoContext.Current.UrlProvider.GetUrl which calls back into the IUrlProvider pipeline
|
||||
// but the specific purpose of this is that a developer is using their own IPublishedContent that returns a specific Url and doesn't go back into the UrlProvider pipeline.
|
||||
//TODO: We could put a try/catch here just in case, else we could do some reflection checking to see if the implementation is PublishedContentBase and the Url property is not overridden.
|
||||
return id == umbracoContext.PublishedRequest.PublishedContent.Id
|
||||
? umbracoContext.PublishedRequest.PublishedContent.Url
|
||||
: null;
|
||||
|
||||
Reference in New Issue
Block a user