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

Forums / Developing with Sitefinity / Urls for content with same title

Urls for content with same title

6 posts, 0 answered
  1. Shawn
    Shawn avatar
    79 posts
    Registered:
    26 Sep 2012
    01 Nov 2010
    Link to this post
    I have a hypothetical question.  I don't think I will run into this issue but I wanted to ask the question.  When I create 2 events with the same title it generates the urls below.

    http://www.mysite.com/event-title.aspx
    http://www.mysite.com/event-title-9325245234.aspx

    How is the number generated at the end of the url?  Is there a way to make it cleaner like

    http://www.mysite.com/event-title-2.aspx
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    01 Nov 2010
    Link to this post
    Hello Shawn,

    Thank you for using our services.

    The content url is generated in a private static method of the ContentUrlRewriterService class. It gets the content and checks if the url is unique, if not it generates the numbers based on the item's ID. Unfortunately this class cannot be overridden due to its protection level.

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Shawn
    Shawn avatar
    79 posts
    Registered:
    26 Sep 2012
    01 Nov 2010
    Link to this post
    All Generic Content has a ContentItemUrl stored in the database.  Is there a way to set the ContentItemUrl before it's saved to the database?  Can I check to see if there is already a piece of  content in the system with the same URL (as specified by the urlRewriteRule in the web.config) and programmatically update the URL before it's saved?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Nov 2010
    Link to this post
    Hi Shawn,

    It is possible to check whether there is an item with the same title, but t you cannot set the url of the content. The urls is checked inside a data class CmsContentBase when the Nolics transaction is executed. There we call ContentUrlRewriterService which formats the url that goes to the database. Also, such a check will cause a performance impact when you have many items.

    You could implement your own service that is called during binding a control populated with data from a given module. Another option is creating a custom module that will use your custom service.
    The service is quite complex. You could implement your own service that inherits from UrlRewriterService. The class provides base implementation for IUrlRewriterService interface. You can override


    GetUrlData method which is used by the cms to know if this url is content item , page etc.
    GetItemUrl get an url, associated with a rewrite parameter. Here you need to get and modify the url
    rewrite paramater  - implement some properties that your item will use as - item ID, item Name. Here you could override ToString() - String, representing the internal state of the parameters

    You have to create a custom class that inherits from UrlRewriteData. This class defines the data that is passed to the HttpContext.Items collection when the url was processed by the url rewrite service. In the constructor you could identify the item rewrite data in a redirected HttpContext.Current.Items.

    Then your public control should inherit IUrlRewriterContainer interface and you need to implement the rewrite service.

    #region IUrlRewriterContainer Members
     
    /// <summary>
    /// Gets an instance of custom rewriting service
    /// </summary>
    /// <returns></returns>
    public IUrlRewriterService GetUrlRewriterService()
    {
        return new CustomRewriteService();
    }
     
      
    #endregion

    Then when you bind the data you could call the url rewrite service

    pseudo code

    if(HttpContext.Current != null)
               {
                   var rewriteData = HttpContext.Current.Items[Constants.RewriteItemId] as CustomRewriteData;
                   if(rewriteData != null)
                   {
                       var rewriteParam = rewriteData.Data as RewriteParameter;
                       if(rewriteParam != null&&
                           rewriteParam.itemID!= Guid.Empty)
                       {
                                    //
                       }
                   }
               }


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Leonard
    Leonard avatar
    19 posts
    Registered:
    01 Dec 2005
    01 Nov 2010
    Link to this post
    Shawn,

    A possible solution would be to update the "urlRewriteFormat" attribute for Events provider in web.config by including Event_Start in the URL format, and eventually to update "urlDateTimeFormat" attribute as well to ensure a unique final URL.

    Unless you need to have different event entries with the same name that start on the same date and time - those two attributes can help achieve a unique, user-friendly URL.

    For instance, to achieve a 1 min "granularity" the attribute values would be:
    urlRewriteFormat="[Event_Start]/[Title].aspx"
    urlDateTimeFormat="yyyy-MM-dd_HH-mm"
  6. Shawn
    Shawn avatar
    79 posts
    Registered:
    26 Sep 2012
    05 Nov 2010
    Link to this post
    Thanks for the recommendation Leanord.  I'm also considering adding a new metadata field who's only purpose is the url.  The event scenario was just an example.  I need this functionality for custom modules that don't have a datetime included in the url.  It's much more generic (like Title) and the possibility of duplicates is much higher.  On save, I could add a custom validator to query for a match against the url metadata field. 
Register for webinar
6 posts, 0 answered