Custom URL Rewriting in 7.5

Vote:
 

Hi, 

WE have a custom url rewriter that inherits from the FriendlyUrlRewriter and this does not work with 7.5 any longer. We have tried changing the functionality to inherit from the hierarchicalUrlRewriterProvider, but this is missing a function: ConvertToInternalInternal. 

My question is how do I recreate this functionality? The functionality is basically as follows : 

protected override bool ConvertToInternalInternal(UrlBuilder url, ref object internalObject)
        {
            bool urlRewritten = false;
            KeyValuePair qsAdditional = new KeyValuePair();

            if (url != null)
            {
                PageReference pageRef = null;

                if (!url.Path.ToLower().StartsWith("/events/"))  // Don't try to resolve a link that starts with 'events' as this has already been rewritten
                {
                    pageRef = TryResolveEventsUrl(url);

                    if (PageReference.IsNullOrEmpty(pageRef))
                    {
                        pageRef = TryResolveBusinessLineClaimsUrl(url, out qsAdditional);
                    }

                    if (!PageReference.IsNullOrEmpty(pageRef))
                    {
                        // Rewrite the url based on the page ref
                        url.Path = new Url(DataFactory.Instance.GetPage(pageRef).StaticLinkURL).Path;

                        // Add the page id back to the querystring
                        url.QueryCollection.Add("id", pageRef.ID.ToString());

                        // Add additional querystring parameters to the internal url
                        url.QueryCollection.Add("epslanguage", ContentLanguage.PreferredCulture.TwoLetterISOLanguageName);

                        // Add any additional querystring parameters
                        if (!String.IsNullOrEmpty(qsAdditional.Key))
                        {
                            url.QueryCollection.Add(qsAdditional.Key, qsAdditional.Value);
                        }

                        urlRewritten = true;
                    }
                }
            }

            if (urlRewritten)
            {
                return true;
            }
            else //Not a custom url so use default rewriting behaviour
            {
                return base.ConvertToInternalInternal(url, ref internalObject);
            }

        }

Thank you! 

Gabor

#132901
Aug 20, 2015 14:20
Vote:
 

Hi,

Did you tried to override TryConvertToInternal method of HierarchicalUrlRewriteProvider?

 public override bool TryConvertToInternal(UrlBuilder url, out CultureInfo preferredCulture, out object internalObject)
    {
      preferredCulture = ContentLanguage.PreferredCulture;
#132907
Aug 20, 2015 15:20
Vote:
 

Thank you Gregorz. I had the ConvertToInternal method implemented, so the tryconvert would have done the same functionality. 

The problem was that the RewriteProvider was not hooked up in the episerver config correctly, and the RewriteModule was not set to EPiServer.Web.RoutingUrlRewriteModule. 

according to the documentation : http://world.episerver.com/documentation/items/developers-guide/episerver-cms/75/routing/routing/ this is what's required to make it work. 

So in Web config, I have a module registered under system.web> httpModules: 

      <add name="UrlRewriteModule" type="EPiServer.Web.RoutingUrlRewriteModule, EPiServer" />

In Episerver.config I set the urlRewrite section up as follows: 

 <urlRewrite defaultProvider="CustomUrlRewriter">
    <providers>
      <clear />
      <add description="EPiServer standard Friendly URL rewriter" name="EPiServerFriendlyUrlRewriteProvider" type="EPIServerFriendlyUrlRewriter,EPiServer" />
      <add description="EPiServer identity URL rewriter" name="EPiServerIdentityUrlRewriteProvider" type="EPiServer.Web.IdentityUrlRewriteProvider,EPiServer" />
      <add description="EPiServer bypass URL rewriter" name="EPiServerNullUrlRewriteProvider" type="EPiServer.Web.NullUrlRewriteProvider,EPiServer" />
      <add name="CustomUrlRewriter" type="CustomUrlRewriter,MyAssemblyName" />
    </providers>
  </urlRewrite>

Thanks for your help!

#132937
Aug 21, 2015 10:08
Vote:
 
<p>Thnaks Gabor for explaining solution.</p> <p>/K</p>
#132953
Aug 21, 2015 12:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.