Url-Rewrite, FriendlyUrl and PartialRouting questions

Member since: 2017

Hi all,

I have a hard time deciding on a strategy here.

Basically I have content that exists in an external service only. There are no Epi-nodes.

So I have one block with a list of the content and one "dummy" detail page which reads in the rest of the content based on a key.

The problem I have, is that I would like to rewrite the url to this "dummy" page to a friendly one. Like /news/details/2017/05/newstitle

All the examples I have found on partial routing, seems to be based on the content existing in a list or some physical form but I only have the detail info once I hit the page (it goes to an external service and fetches info).

If all I require, is a friendly url like the above, no need for any kind of local storage. What is the best strategy here?

Thank you in advance.

#180226 Jul 03, 2017 19:15
  • Member since: 2007


    I would go with a partial router, since your detail page is a page in the CMS. This example http://world.episerver.com/documentation/developer-guides/CMS/routing/partial-routing/Example-of-News-partial-routing/ actually shows how to route to "external" content. In that example, instead of calling the DDS to see if the news item exists in the database, you call your external service.

    #180235 Jul 03, 2017 22:39
  • Member since: 2017

    Hi Johan,

    Thank You. I do have some problems with getting that example working on my end though. Could be that I am a bit green in the Epiworld (not .net).

    1) My detail page is deeper in the hierarchy than below the startpage. How do I set that correctly? Or do I have to put the dummypage just below the startpage?

    2) How to best form url-links to the news from the list. This list is a block that could be anywhere. It is also multilanguage. So I have to form the urls similar to /details/year/date/title (this actually a vue script).

    So. How to best construct this urls? Is there a built in slug generator for titles etc? 

    My goal is to use as much "epi" best practice as possible here. 

    Thanks again.

    #180254 Edited, Jul 04, 2017 11:51
  • Member since: 2007

    1, Instead of the code below, you have to have a setting or other logic that fetches your detail page. It could be a setting in appSettings or a setting on the startpage

    var newsPage = context.Locate.ContentLoader().GetChildren<NewsContainer>(ContentReference.StartPage).GetFirstOrDefault();

    2, The partial router handles both outgoing and incoming URLs. The outgoing URL is generated in the GetPartialVirtualPath method.

    The last part of the slug it's up to you to generate in the method mentioned above. The first part will be to you detail page.

    #180262 Jul 04, 2017 14:37
  • Member since: 2017

    Unfortunatelly. This example seems to be obsoleted. I can't seem to use this method at all in code.


    My point here is that I need to construct the url in the api controller. It seems I need actual IContent here. 

    Maybe someone at Epi could update the sample if code is obsolete?

    The only method I can access, is GetVirtualPath but that requires actual content.

    #180275 Edited, Jul 05, 2017 10:45
  • Member since: 2007

    I've not tested this. But don't you pass your custom news article object in that method, then it will resolve which partial router to use and call the method GetPartialVirtualPath in the partial router? No need for IContent. 

    #180276 Edited, Jul 05, 2017 10:53
  • Member since: 2017

    I can't seem to access any of the methods at all. I don't get this at all.

    I looked at the sample Jon created here but that too relies on physical pages.


    I would love to have that NonContent method back.

    #180284 Jul 05, 2017 11:14
  • Member since: 2007

    Which methods!? Either dependency inject UrlResolver or use the static one UrlResolver.Current.GetVirtualPathForNonContent(). 

    #180285 Jul 05, 2017 11:21
  • Member since: 2017

    Ah :). Lets try that.

    #180288 Jul 05, 2017 11:30