+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Get language specific url's

Get language specific url's

6 posts, 0 answered
  1. Peter
    Peter avatar
    10 posts
    Registered:
    24 Aug 2008
    05 Apr 2009
    Link to this post
    Hey guys,

    I'm trying to create an XML sitemap web handler, and I have problems getting out the language specific Url's of all the pages in the system. Can you help me with that?

    I'm currently doing this:

     

    foreach (CmsPage page in pages) {
        string url = page.DefaultUrl.Url;
    }

    Buy that only gives me the generic Url for one page.

    Kind regards,

    Peter

     

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Apr 2009
    Link to this post
    Hello Peter,

    Please use UrlHelper class.Check out the code below:

     protected void Button1_Click1(object sender, EventArgs e) 
        { 
            CmsManager manager = new CmsManager(); 
            IList listofPages = manager.GetPages(); 
            foreach (IPage page in listofPages) 
            { 
                ICmsPage page1 = manager.GetPage(page.ID, trueas ICmsPage; 
                if (page1 != null
                { 
                    // get page url 
                    Response.Write(UrlHelper.ResolveUrl(page1.DefaultUrl.Url) + "<br />"); 
     
                } 
            } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Peter
    Peter avatar
    10 posts
    Registered:
    24 Aug 2008
    07 Apr 2009
    Link to this post
    Hi Ivan,
    This gives me the total number of pages in the system. But the Url's are still not prefixed with a language specific part. How do I get the language prefix for each page in that loop? (I've tried both Telerik.CrawlerSitemaps.UrlHelper and Telerik.Cms.Web.UrlHelper with almost same result) I'm looking for a result like /virtualdir/en/welcome.aspx


    Here's my code:

                    CmsManager manager = new CmsManager();
                    IList listofPages = manager.GetPages();
                    var str = "";
                    foreach (IPage page in listofPages)
                    {
                        ICmsPage page1 = manager.GetPage(page.ID, true) as ICmsPage;
                        if (page1 != null)
                        {
                            // get page url 
    str = str + Telerik.CrawlerSitemaps.UrlHelper.ResolveUrl(page1.DefaultUrl.Url) + "<br />";

                        }
                    } 

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Apr 2009
    Link to this post
    Hi Peter,

    I am not sure why you use CrawlerSitemap. You should use CultureInfo class and UrlHelper.ResolveLanguageUrl to get all pages versions.

    Here is a sample:

      CmsManager manager = new CmsManager(); 
     
            int totalRows; 
            IList listofPages = manager.GetPages(0, int.MaxValue, string.Empty, ListSortDirection.Ascending, out totalRows); 
            foreach (CmsPageInfo page in listofPages) 
            { 
                CultureInfo culture; 
                if (page.LangID == CultureInfo.InvariantCulture.LCID) 
                    culture = LocalizationManager.DefaultCulture; 
                else 
                    culture = CultureInfo.GetCultureInfo(page.LangID); 
     
                string url = ResolveUrl( 
                    UrlHelper.ResolveLanguageUrl( 
                        page.CmsPage.DefaultUrl.Url, 
                        culture)); 
     
                Response.Write(url + "<br />"); 

    The output is:

    /Sitefinity_3_6_1870/bg/Page.aspx
    /Sitefinity_3_6_1870/fr/Page.aspx
    /Sitefinity_3_6_1870/es/Page.aspx

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Jan
    Jan avatar
    39 posts
    Registered:
    22 Jan 2010
    14 Apr 2011
    Link to this post
    Hi

    I'm trying to use this, but in an indexprovider
    The indexprovider reads all post from a custom sitemapprovider and gets a sitemap node.
    From that I retrieve an url in the form ~/catalog/subcatalog/file.aspx

    When I run the
    url = UrlHelper.ResolveLanguageUrl(url, new CultureInfo(Culture));

    I get some strange result.
    For the default language (swedish) I still have the ~/catalog/subcatalog/file.aspx as Url.
    For english I get a https://site.com443/catalog/subcatalog/file.aspx

    I have https turned on for the admin pages, but I don't use if for the ordinary pages.

    I also use the domainname for localization.  .com/.se/.fi/.dk

    What I expected to retrieve was these two lines
    http://site.se/catalog/subcatalog/file.aspx
    http://site.com/catalog/subcatalog/file.aspx

    What I do with these is that I do a page request and parse the answer and send it to the indexer.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    20 Apr 2011
    Link to this post
    Hi Jan ,

    We use relative paths, so basically we do not save the host location. We resolve all urls relatively to avoid issues related to changing the website location and its host.  You can use the HttpContentext to the the host that is used when a request to your page is made.

    Regards,
    Ivan Dimitrov
    the Telerik team

Register for webinar
6 posts, 0 answered