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

Forums / Developing with Sitefinity / suffixing items to the url

suffixing items to the url

4 posts, 0 answered
  1. Nick
    Nick avatar
    91 posts
    Registered:
    04 Aug 2008
    13 Aug 2008
    Link to this post
    i need to suffix a unique number to any and all news items. previously i did this by changing the newslist control in the following way

    <%#DataBinder.Eval(Container.DataItem, "Url").ToLower()%>_<%#Math.Abs(DataBinder.Eval(Container.DataItem, "Url").GetHashCode()).ToString()%>.html

    i wrote a http module to strip off the suffix when the url was requested

    the urls look something like this int the news list
    http://www.mycompany.com/news/my-news-article_1234567.html
    and the article delivered
    http://www.mycompany.com/news/my-news-article.html

    there must be a better way of doing this; anybody got any ideas?

    thanks
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    13 Aug 2008
    Link to this post
    Hello nick,

    Every news item already has a unique number assigned to it, it's ID property. The simplest way of having that number in the URL is to modify the urlRewriteFormat of the news provider in the web.config so that it looks like this:

    <add name="News" urlRewriteFormat="[Publication_Date]/[Title]_{ID}.aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_" visible="False" defaultMetaField="Title" securityProviderName="" allowVersioning="True" applicationName="/News" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.News.Data.DefaultNewsProvider, Telerik.News.Data" /> 

    Notice, how I've added the _{ID} part. In case you are wondering why I've used curly braces instead of square ones, the reason is following: Square braces are used when you want to display a meta key (Title, Author, Source...) in the URL, while curly braces are used when you want to display the property of the content item (ID, Provider...).

    I hope you will find this information helpful. Let us know if there is anything else we can do for you.

    Kind regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Nick
    Nick avatar
    91 posts
    Registered:
    04 Aug 2008
    14 Aug 2008
    Link to this post
    thanks ivan
    i thought i was going to have a problem with this solution as i thought the id was a guid, but it works a treat!

    :O)
  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    14 Aug 2008
    Link to this post
    Hi nick,

    Glad to be able to help. Let us know if there is anything else we can do for you.

    Kind regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
4 posts, 0 answered