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

Forums / Developing with Sitefinity / Lowercasing news & events urls

Lowercasing news & events urls

11 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Nov 2010
    Link to this post
    Hi,

    The URL for each news article or event is automatically created by sitefinity based on the title. How can I ensure this is created as lowercase?

    Wherever my user controls are rendering hyperlinks to news / events I am using ToLower, but it would be far safer knowing that they were actually being created as lowercase so that programmatically I dont miss one.

    thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 Nov 2010
    Link to this post
    Hello higgsy,

    When you create or update the item you can save the title to lowercase. There are static events of ContentManager. Executed or ContentManager.Executing that you can use. Another option is creating a custom HttpModule or HttpHandler from where you can set the url string to lower. The third option is using AdvencedUrlRewriting  module, but you have to write a rule for each letter from the alphabet, because there is not a rule that will matches the entire string for uppercase letters and then convert them to lowercase.

    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
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Nov 2010
    Link to this post
    Hi Ivan,

    The first option sounds like an option. I have seen code for ContentManager.Executed placed in the global.asax, however how would I set the title to lowercase. Is there some sort of contentmanager override?

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    04 Nov 2010
    Link to this post
    Hello higgsy,

    Below is a sample code

    void Application_Start(object sender, EventArgs e)
      {
          // Code that runs on application startup
          Telerik.Cms.Engine.ContentManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(ContentManager_Executed);
      }
     
      void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e)
      {
          if (e.CommandName == "UpdateContent" || e.CommandName == "CreateContent")
          {
              var providerName = (e.Data as Telerik.Cms.Engine.Data.CmsContentBase).ProviderName;
              if (providerName == "News")
              {
                  var itemID = e.ItemID;
                  var manager = new ContentManager(providerName);
                  var content = manager.GetContent(itemID);
                  var currentTitle = content.GetMetaData("Title");
                  content.SetMetaData("Title", currentTitle.ToLower());
                  manager.SaveConetnt(content);
              }
          }
      }


    All the best,
    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. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    05 Nov 2010
    Link to this post
    Hi Ivan,

    I've just looked at this solution but there is a major problem with it. I can't set the "title" field to lowercase as this would change the content that the user had entered - i'm looking to change the url not the title. I realise the URL is generated from the title, but I can't just lowercase the actual title - the content editors would be slightly angry!

    As there isnt a sitefinity field for the url, presumably that discounts the ContentManager.Executed method as this can't change the url?

    Does that leave just the handler or advanced url rewriting methods?

    Thanks
    higgsy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    05 Nov 2010
    Link to this post
    Hello higgsy,

    Then use handler or rewriting which actually are the better option, because you do not commit the IContent into a transaction.

    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
  7. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    05 Nov 2010
    Link to this post
    There is another possibility i guess. I could create another meta data field for the news module.

    <add key="News.Url" valueType="ShortText" visible="True" searchable="false" sortable="True" defaultValue="" />

    Then using the ContentManager.Executed method I could update the new Url field to store the lowered version of the title. And finally change the provider urlrewriting format to:

    <add name="News" urlRewriteFormat="[Publication_Date]/[Url].aspx" urlDateTimeFormat="yyyy" urlWhitespaceChar="-" visible="False" defaultMetaField="Title" securityProviderName="" allowVersioning="True" allowWorkflow="True" applicationName="/News" versioningProviderName="" commentsModeration="true" connectionStringName="GenericContentConnection" type="Telerik.News.Data.DefaultNewsProvider, Telerik.News.Data" />

    What do you think?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    05 Nov 2010
    Link to this post
    Hi higgsy,

    This looks like as another option as well.

    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
  9. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    05 Nov 2010
    Link to this post
    Ok, thanks for the advice - i'll play around with a couple of options and see what works best. Is there any information on creating a handler for sitefinity anywhere?
  10. gopalraman gopal
    gopalraman gopal avatar
    52 posts
    Registered:
    03 Dec 2009
    05 May 2011
    Link to this post
    Hi

    After executing the bellow code, when manager.SaveContent(content);
    is fired, it call back the ContentManager_Executed event again and again and finally
    i got the following error "An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll". how to overcome this issue?

    void Application_Start(object sender, EventArgs e)
      {
          // Code that runs on application startup
          Telerik.Cms.Engine.ContentManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(ContentManager_Executed);
      }
     
      void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e)
      {
          if (e.CommandName == "UpdateContent" || e.CommandName == "CreateContent")
          {
              var providerName = (e.Data as Telerik.Cms.Engine.Data.CmsContentBase).ProviderName;
              if (providerName == "News")
              {
                  var itemID = e.ItemID;
                  var manager = new ContentManager(providerName);
                  var content = manager.GetContent(itemID);
                  var currentTitle = content.GetMetaData("Title");
                  content.SetMetaData("Title", currentTitle.ToLower());
                  manager.SaveConetnt(content);
              }
          }
      }
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    05 May 2011
    Link to this post
    Hi,

    Try using the continuing event - Executing

    All the best,
    Ivan Dimitrov
    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
Register for webinar
11 posts, 0 answered