November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I believe you need to play around with the URL rewriter to break a URL down into its internal representation - this contains an "id" parameter that you can grab a PageReference from.
Something like the code below should sort you out:
//* Convert an external URL to an internal URL
UrlBuilder newURL = new UrlBuilder("http://EPiServer6TestSite/Home-page/");
Global.UrlRewriteProvider.ConvertToInternal(newURL);
//* Now fetch the ID and get a page reference
PageReference result;
string pageIDslug = newURL.QueryCollection["id"];
if (!string.IsNullOrEmpty(pageIDslug))
{
string[] splitSlug = newURL.QueryCollection["id"].Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
int pageId;
if (splitSlug.Length > 0 && int.TryParse(splitSlug[0], out pageId))
{
//* Do we have a work page ID?
int workPageId;
if (splitSlug.Length > 1 && int.TryParse(splitSlug[1], out workPageId))
{
result = new PageReference(pageId, workPageId);
}
else
{
result = new PageReference(pageId);
}
}
}
PageReference.ParseURL() could be another choice. Need to convert it to an internal URL first though.
Tahir
Another solution - very similar to above too . It has same concept to covert the Url to internal state.
UrlBuilder urlBuilder = new UrlBuilder(Url);
object pageReference;
Global.UrlRewriteProvider.ConvertToInternal(urlBuilder, out pageReference);
//or use PageReference.ParseUrl() here
if (pageReference != null && pageReference is PageReference)
{
//ur page reference logic here
}
"/mysite/en-gb/child/grandchild""/mysite/en-gb/child/grandchild"On a similar note, a complete newbie question by I can't seem to find the answer to this...
How do I get a reference to a page by absolute URL, e.g. "/mysite/child/grand-child"
PageReference.ParseURL looks like the correct method, but what am I missing?
var url = "/mysite/child/grand-child";
var pageRef = PageReference.ParseUrl(url); <-- returns PageReference.EmptyReference
var page = DataFactory.Instance.GetPage(pageRef);
Eventually I will end up with several sites and languages, so the tree structure would be like so for example, so ideally i'd like to be able to retrieve the reference relatively...
"/mysite1/en-gb/child/grandchild"
"/mysite1/fr-fr/child/grandchild"
"/mysite2/en-gb/child/grandchild"
"/mysite2/it-it/child/grandchild"
"/mysite3/en-gb/child/grandchild"
"/mysite3/es-es/child/grandchild"
Let me know if you need info.
thanks
How can we get the PageReference Object from the friendly URL(string). I tried PermanentLinkMapStore, but failed... Can any body please guide.
Thanks