Try our conversational search powered by Generative AI!

Get PageData / Content from Url

Vote:
 

I need to get the PageData from the friendly Url. E.g. "/my-page". I do not have the host part of the url.

I've tried:

EPiServer.Web.Routing.UrlResolver.Current.Route

PageReference.ParseUrl

PermanentLinkUtility.GetGuid

Global.UrlRewriteProvider.ConvertToInternal

Any other suggestions?

#194392
Jun 20, 2018 10:33
Vote:
 

Below is a quick piece of code I have knocked up which may solve this for you (I haven't got a development environment available at this moment so this is coded from memory):

public static PageData PageFromURL(string url)
{
    var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
    IContent contentData = urlResolver.Route(new UrlBuilder(url));

    PageReference current_ref = new PageReference(contentData.ContentLink.ID);

    PageData current = DataFactory.Instance.GetPage(current_ref);

    return current;
}
#194394
Jun 20, 2018 10:56
Vote:
 

@Darren: your code is correct but can be improved 

var pageData = urlResolver.Route(new UrlBuilder(url)) as PageData;
#194396
Jun 20, 2018 11:30
* 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.