Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

IUrlResolver.GetUrl pages with custom action cache issue

$
0
0

It seems that together with https://world.episerver.com/documentation/Release-Notes/ReleaseNote/?releaseNoteId=CMS-15789 was introduced a bug.

In IUrlResolver there is a method 

    string GetUrl(
      ContentReference contentLink,
      string language,
      UrlResolverArguments urlResolverArguments);

UrlResolverArguments doesn't have a dedicated field for action in the page controller. So, action could be passed as a part of RouteValues dictionary.

In the implementation for UrlResolver UrlResolverArguments are converted to VirtualPathArguments.

And this VirtualPathArguments class already has a dedicated property for Action and that property is used in GetHashCode() method which is used in cache key generation.

However action from RouteValues dictionary is not copied to Action property and during hash code calculation there is a logic which excludes node, action and language route parametwers from hash code calculation.

So, my question is if it's a kown behaviour and custom actions are no longer supported or it's a bug and I just need to wait for a fix?

Meanwhile, I created an overloaded implementation for UrlResolver

public class CustomUrlResolver : DefaultUrlResolver
	{
		public CustomUrlResolver(
			RouteCollection routes,
			IContentLoader contentLoader,
			ISiteDefinitionRepository siteDefinitionRepository,
			TemplateResolver templateResolver,
			IPermanentLinkMapper permanentLinkMapper,
			IContentLanguageSettingsHandler contentLanguageSettingsHandler,
			IContentUrlCache contentUrlCache,
			IContextModeResolver contextModeResolver,
			IRequestHostResolver requestHostResolver)
			: base(
				routes,
				contentLoader,
				siteDefinitionRepository,
				templateResolver,
				permanentLinkMapper,
				contentLanguageSettingsHandler,
				contentUrlCache,
				contextModeResolver,
				requestHostResolver
			)
		{
		}
		/// <summary>
		///EPiServer.Web.Routing.Internal.ContentUrlCacheContext doesn't take into account action if it's a part
		///of RouteValues dictionary. Remove that implementation as soon as it's fixed.
		/// </summary>
		/// <param name="contentLink"></param>
		/// <param name="language"></param>
		/// <param name="virtualPathArguments"></param>
		/// <returns></returns>
		public override string GetUrl(
			ContentReference contentLink,
			string language,
			VirtualPathArguments virtualPathArguments)
		{
			if (virtualPathArguments.RouteValues != null &&
			    virtualPathArguments.RouteValues.ContainsKey(RoutingConstants.ActionKey))
			{
				virtualPathArguments.Action = virtualPathArguments.RouteValues[RoutingConstants.ActionKey] as string;
			}
			return base.GetUrl(
				contentLink,
				language,
				virtualPathArguments
			);
		}
	}

But such customizations is not something which I'd like to see and maintain during EPiServer upgrades in my project:)


Viewing all articles
Browse latest Browse all 8020

Trending Articles