Try our conversational search powered by Generative AI!

Custom URL RewriteProvider in EPiServer 7

Vote:
 

Hi!

 

I'm having some issues with upgrading the current EPi6R2 project functions to EPiServer 7 functions.

One of the issues include a custom FriendlyUrlRewriteProvider. The overwritten method looks like this:

 

        protected override bool ConvertToExternalInternal(EPiServer.UrlBuilder url, object internalObject, System.Text.Encoding toEncoding)
        {
            // We call the base implementation and if it returns true
            // then we do our magic.
            if (base.ConvertToExternalInternal(url, internalObject, toEncoding))
            {
                // The following handling rules are copied
                // from the base method.
                PageReference pageLink = internalObject as PageReference;
                if (pageLink == null)
                {
                    pageLink = PermanentLinkUtility.GetPageReference(url);
                }
                if (PageReference.IsNullOrEmpty(pageLink))
                {
                    this.TryConvertPermanentLink(url, out pageLink);
                    if (pageLink == null)
                    {
                        return true;
                    }
                }

                // Do something if you get the PageReference - Reference is needed to determine pagetypes 

 

The main issue seems to be that the PermanentLinkUtility or any other way I've used to parse the Url/PageId to a PageReference doesn't seem to pull through. Any ideas on how to resolve the PageType of the current page in some otherway?

Cheers,

 

#75893
Oct 10, 2013 8:08
Vote:
 

An update to the matter - i got it fixed.

The Reflector told me that PageReferences have been changed to ContentReferences and by changing the following statements:

        protected override bool ConvertToExternalInternal(EPiServer.UrlBuilder url, object internalObject, System.Text.Encoding toEncoding)
        {
            // We call the base implementation and if it returns true
            // then we do our magic.
            if (base.ConvertToExternalInternal(url, internalObject, toEncoding))
            {
                // The following handling rules are copied
                // from the base method.
                //PageReference pageLink = internalObject as PageReference;
                ContentReference pageLink = internalObject as ContentReference;
                if (pageLink == null)
                {
                    //pageLink = PermanentLinkUtility.GetPageReference(url);
                    pageLink = PermanentLinkUtility.GetContentReference(url);
                }
                if (PageReference.IsNullOrEmpty(pageLink))
                {
                    this.TryConvertPermanentLink(url, out pageLink);
                    if (pageLink == null)
                    {
                        return true;
                    }
                }

                // Do something if you get the PageReference - Reference is needed to determine pagetypes 

    

And the ContentReference needs to be converted to PageReference:

 

                PageData page = DataFactory.Instance.GetPage(pageLink.ToPageReference());

 

Hope this helps someone ;)

#75895
Oct 10, 2013 9:39
Vote:
 

Good that you found a solution yourself.

But generally, using the events ConvertingToExternal, ConvertedToExternal, ConvertingToInternal and ConvertedToInternal and/or UrlRewriteModules is better since it mostly gives you less headache when doing maintenance and upgrading.

#75901
Oct 10, 2013 12:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.