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

Forums / General Discussions / change URL's?

change URL's?

23 posts, 0 answered
  1. NuToSitefinity
    NuToSitefinity avatar
    140 posts
    Registered:
    01 Sep 2010
    23 Feb 2011
    Link to this post
    I created a usercontrol to show my news items, (the current news widget won't work within my display). I'm able to pull out the news title and the urlname, however the urlname is just the title of my news item. How can I get the correct URL for my news item like the out of the box news widget has?

    here is what I'm referring to:
    if I enter in a news item in the backend and title it: The following items are being discontinued, the url for that item shows up as /2011/02/23/the-following-items-are-being-discontinued

    if I show that same news item in my user controls, the url is:
    /the-following-items-are-being-discontinued

    and when I click on it nothing happens, where when I click on the URL in the news widget, I can see my news.

    how can I get the correct URL for each news item within my user control?
    here is that code that i used for the news:

     

    var news = from n in App.WorkWith().NewsItems()
                          where n.Status == ContentLifecycleStatus.Live
                          orderby n.Title
                          select n;

     



    I then bind it to my datalist and show [title] and [urlname], what should I be using for the URL?

  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    24 Feb 2011
    Link to this post
    Hello CsharpGuy,

    Thank you for contacting Telerik Support.

    You can get the default url by subscribing to the DataList control's ItemDataBound event. Consider the sample bellow:
    void  dt_ItemDataBound(object sender, DataListItemEventArgs e)
       {
           if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
           {
               NewsItem itemBound = (NewsItem)e.Item.DataItem;
               string url = itemBound.Urls.Where(u=> u.RedirectToDefault == false).FirstOrDefault().Url;
               //this will give you /2011/02/23/the-following-items-are-being-discontinued
               //then you need to construct a link to your page which contains news control and append the url to this link
           }
       }
    Please pay attention to the last comment - the string url will refer to the default URL of the news item, but you need to reference the link to your page containing the news control, in order to make the news visible when accessed from your custom control.

    I hope this information helps. Please let me know if I can assist you any further with this service request. Thank you in advance.

    Greetings,
    Boyan Barnev
    the Telerik team
  3. NuToSitefinity
    NuToSitefinity avatar
    140 posts
    Registered:
    01 Sep 2010
    24 Feb 2011
    Link to this post
    wow, never would have figured that out. You guys should build a code library or something and have real world working examples like this. So far the v4 documentation isn't that great and has nothing like this in it.


    Is something like this possible to pull out all of my pages?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    25 Feb 2011
    Link to this post
    Hi CsharpGuy,

    We started working on the documentation articles, so the manual is going to be updated very soon with new samples and How tos. As for the pages, there is implementation for additional urls for pages that can be set from the UI, so you can specify completely differentiate url to resolve the same page with no coding. The feature will be included in the Q1 release.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
  5. Taha
    Taha avatar
    6 posts
    Registered:
    02 Mar 2011
    30 Mar 2011
    Link to this post
    That codes works for me. I also used myNewsItem.Urls[0].Url and that returns the right Url. 
    However, 
    how can I control the URL path. mainly I don't want dates in the URL (in general I need to flexibly do the paths ) 
    example: 
    I want to change "/2011/03/29/how-to-write-code"  to --> "/code/how-to-write-code"

    Any tips, hints.

    Thanks 
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    30 Mar 2011
    Link to this post
    Hello Taha,

    There is an option to change the url format of the content modules go to Administration >> Settings >> Advances and expand the News node. Then add urlFormat parameter to the provider. For Key enter "urlFormat". For value enter "/[UrlName]". All without the quotes.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
  7. Dave Brace
    Dave Brace avatar
    1 posts
    Registered:
    29 Jun 2009
    30 Mar 2011
    Link to this post
    Can we change the urlFormat for blogs as well?  I tried adding the urlFormat key for the blog provider and it did not update my blog URL's when using a blog posts control.
  8. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    30 Mar 2011
    Link to this post
    @Dave, I'm pretty sure you need to a) restart your web app (aka edit the web.config) and b) it will only be applied to new blogs going forward. I did this same change to the Libraries as I didn't think the date in the url to an image made any sense. It would only work for new albums, so I basically had to delete all my images and albums and start from scratch. Hope that helps.

    Phill
  9. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    03 Apr 2011
    Link to this post
    Hello Ivan,

    I have the same issue of Dave, I changed the urlFormat for the blogs and I created new posts but still the url of the new blog posts have the format "date/urlName"

    Did I miss anything?

    Thanks.
  10. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    04 Apr 2011
    Link to this post
    Hello AmrElsayed,

    After saving the changes to urlFormat, did you restart the application? You need to do this, because we are not restarting it automatically on adding the key for urlFormat.  Please try modifying the web.config (just press space couple of times and then save) and then make a new blog post and inform me if the issue still persists.

    Greetings,
    Boyan Barnev
    the Telerik team

  11. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    04 Apr 2011
    Link to this post
    Helo Boyan,

    yes, I added the "urlFormat" parameter, then I restarted the application (and I tried to make any changes in the web.config), then I created a new post in a blog.
    the url of the new post is still in the format "date/urlName".

    I am using version 4.0.1210.0

    Thanks.


  12. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    04 Apr 2011
    Link to this post
    I've mentioned already that I had this issue with Libraries and Albums. The key was that after changing the URL format I had to delete the album and start from scratch. I would assume this is the same as Blogs, you can just create a new blog post you need to delete the blog and create a new one, then create a blog post and see if it works. Have you done that?

    Cheers,
    Phill
  13. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    04 Apr 2011
    Link to this post
    Hello AmrElsayed,

    Indeed there is a registered  bug concerning this behavior, which is for blogs only. Generally the url should be changed without deleting the old data. The bug ID is #109623 and we'll be working on fixing it. I apologize for the inconvenience caused.

    All the best,
    Boyan Barnev
    the Telerik team

  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    04 Apr 2011
    Link to this post
    Hello AmrElsayed,

    Indeed there is a registered  bug concerning this behavior, which is for blogs only. The bug ID is #109623 and we'll be working on fixing it. I apologize for the inconvenience caused.

    All the best,
    Ivan Dimitrov
    the Telerik team

  15. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    04 Apr 2011
    Link to this post
    Hello,

    So, Is there any solution that I can do for now (till the bug is fixed) to change the blog post's url format to "urlName" only (without the date portion)?

    Another question please, is this bug is scheduled to be released with the next official release of Q1 in April 13th?

    Thanks.
  16. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    05 Apr 2011
    Link to this post
    Hi AmrElsayed,

    I've checked the bug status but we are currently working on bugs with higher status, so I cannot guarantee you if this will be included in the Q1 release or in one of the later internal releases.
    Inspecting this issue further it seems that the setting does not apply, because the value for urlFormat is hard coded in the source code. What you can do for now is to create a custom provider for blogs and inheriting from
    OpenAccessBlogProvider and override the GetUrlFormat method, specifying the desired urlFormat. Please find below the original implementation from the source:
    /// <summary>
     
    /// Gets the url format for the specified data item that implements <see cref="ILocatable"/> interface.
     
    /// </summary>
     
    /// <param name="item">The locatable item for which the url format should be returned.</param>
     
    /// <returns>
     
    /// Regular expression used to format the url.
     
    /// </returns>
     
    public override string GetUrlFormat(ILocatable item)
     
    {
     
    if (item.GetType() == typeof(Blog))
     
    return "/[UrlName]";
     
    else if (item.GetType() == typeof(BlogPost))
     
    return "/[Parent.UrlName]/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]";
     
    else
     
    return base.GetUrlFormat(item);
     
    }

    You can change the
    return "/[Parent.UrlName]/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]";
    line to
    return "/[Parent.UrlName]/[UrlName]";
    to achieve the desired functionality, just note that this might result in errors related to items having the same URL, if you have blog posts with the same title and parent.


    All the best,
    Boyan Barnev
    the Telerik team

  17. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    06 Apr 2011
    Link to this post
    Hello Boyan,

    I created the custom provider.
    Then I changed the "ProviderType" of the blogs from "Sitefinity>Administration>Settings>Advanced>Blogs>Providers>OpenAccessDataProvider" to the fully qualified name of my custom provider.

    I restarted the application but there are no changes, did I miss anything?

    Thanks.
  18. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    07 Apr 2011
    Link to this post
    Hi AmrElsayed,

    Did you test this functionality by creating a new blog post? The URLs of the already existing blog posts will not be changed unless they are opened for edit and then saved, so that their URLs can be recompiled. Please try creating a new blog post and inform me if the problems still persist.

    Regards,
    Boyan Barnev
    the Telerik team

  19. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    07 Apr 2011
    Link to this post
    Thanks a lot Boyan.
    It works well.

  20. Asit
    Asit avatar
    87 posts
    Registered:
    07 Nov 2009
    18 Aug 2011
    Link to this post
    Hi,

    I m using one user control for news listing, all seems to working fine except the news URL.

    If the news title contains .(Dot) at the end, then it shows me 404 page not found error.
    I can remove the dot from the ending, but Can you please tell me this the single character i need to remove or is there other character also.

    But when using default sitefinity news public control it redirects the page to listing page.

    Thanks
    Asit
  21. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    18 Aug 2011
    Link to this post
    Hello Asit Pani,

    The problem might be due to the customized urlFormat, the dot (.) character does not get caught by the regular expression we apply when generating URLs on content items creation, so it will be constructed with a dot inside, which results in invalid URL. However I have tested the reported behavior on a new project created with our latest officially supported version - Sitefinity 4.2 and applied a urlFormat of /test/[Title] and created a news arcticle with title "Title." Using the custom URL formatiing, the URL of the article was: http://localhost:60876/mypage2/test/Test which excluded the special character, and no 404 was returned.

    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  22. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    05 Sep 2011
    Link to this post
    Hey everyone,

    I worked through this challenge this past weekend for a personal project.

    I have a blog called "Topics" in Sitefinity, and I wanted the URL's for this blog to look like this:

    http://mywebsite.com/topics/this-is-my-blog-post

    By default Sitefinity creates URL's that look like this:

    http://mywebsite.com/topics/topics/2011-09-05/this-is-my-blog-post

    As described above, the urlFormat property is not applicable to blog posts; even if it were applicable it wouldn't be possible to have different URL formats for different blogs.  (I have others blogs that I want to use the traditional URL format.)

    --

    My solution was to replace Sitefinity's default OpenAccessBlogProvider with the following custom blog provider:

    using Telerik.Sitefinity.Modules.Blogs.Data;
    using Telerik.Sitefinity.Blogs.Model;
     
    namespace SitefinityWebApp.Extensions.Providers
    {
        public class BlogProvider : OpenAccessBlogProvider
        {
            public override string GetUrlFormat(Telerik.Sitefinity.GenericContent.Model.ILocatable item)
            {
                if (item.GetType() == typeof(Blog))
                {
                    return "/[UrlName]";
                }
     
                if (item.GetType() == typeof(BlogPost))
                {
                    // If this is the "Topics" blog then eliminate all parameters from the URL.
                    // Example:  http://mywebsite.com/topics/workflow
                    var blogItem = (BlogPost)item;
                    if (blogItem.Parent.UrlName == "topics")
                    {
                        return "/[UrlName]";
                    }
     
                    return "/[Parent.UrlName]/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]";
                }
                return base.GetUrlFormat(item);
            }
        }
    }

    I've not done extensive testing on this, but it seems to be working as expected.  The existing blog posts seem to work fine and Sitefinity's widgets also work fine with this custom blogs provider.

    As others noted, the URL's for old blog posts do not automatically get updated.  To update the URL's you can manually click through each blog post and re-save it.  Or you can run this code (use at your own risk!!!) in a small ASPX page:

    using System;
    using System.Linq;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Modules.Blogs;
    using Telerik.Sitefinity.Blogs.Model;
     
    namespace SitefinityWebApp.Extensions
    {
        public partial class test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                var manager = BlogsManager.GetManager();
                foreach (var post in App.WorkWith().BlogPosts().Get().ToList())
                {
                    Response.Write(post.Title + "<br />");
                    var editPost = manager.GetBlogPost(post.Id);
                    manager.RecompileItemUrls<BlogPost>(editPost);
                    manager.Lifecycle.Publish(manager.Lifecycle.GetMaster(editPost));
                    manager.SaveChanges();
                }
            }
        }
    }

    That's it.  This is my own personal project and testing, so please be careful with this code.  When in doubt, make a backup.   :)

    Gabe
    ================
  23. Marco
    Marco avatar
    11 posts
    Registered:
    19 Mar 2015
    09 Jun 2015
    Link to this post
    Hi all,
    I followed the steps. The thing is when we preview the draft or unpublished blog it throws a 404.
    The Sitefinity URL query rules for preview no longer show. Is there a fix for this?
23 posts, 0 answered