November Happy Hour will be moved to Thursday December 5th.

Get simple address for page

Vote:
 

I want to get the simple address for a given page. So far, I've come up with the code below, which obviously don't work. Can someone please help me? Thanks!

 

protected string SimpleAddress(PageData page)
{
UrlBuilder ub = new UrlBuilder(page.LinkURL);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(ub, page.PageLink, System.Text.UTF8Encoding.UTF8);
string url = ub.ToString();

return url;
}
#21803
Jul 09, 2008 16:38
Vote:
 

Seems I was pointed in the wrong direction before. Of course you can access the simple address through the propertyname "PageExternalUrl".

Howeve, the url looks like this:

http://localhost/templates/pages/sitemap

instead of:

http://localhost/sitemap

meaning the PageExternalUrl looks for the folder structure and then adds the simple url..

How can you solve this in an appropriate way? 

#21804
Jul 09, 2008 17:22
Vote:
 

Hi Martin!

I did a quick test and the PageExternalUrl property

string s = page["PageExternalUrl"] 

and it returned the expected value, which in your case would be "sitemap".

So all you should need to do is something like the following to get an the complete url:

Configuration.Settings.Instance.SiteUrl.ToString() + page["PageExternalUrl"];

Regards

Per Gunsarfs

#21820
Jul 10, 2008 13:20
Vote:
 

Here is a sample code snippet for retrieving the simple address for a page:

http://labs.episerver.com/en/Blogs/Ted-Nyberg/Dates/112276/8/How-to-get-the-simple-address-of-a-page-in-EPiServer/

#22771
Aug 15, 2008 10:52
Vote:
 

Martin, the reason for your inaccurate URL is that the simple address doesn't include a leading slash by default.

#22772
Aug 15, 2008 11:14
* 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.