Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Moran 277 posts 885 karma points
    Sep 27, 2014 @ 14:27
    Moran
    0

    Writing umbracoUrlAlias using C#

    Hi Is There a way to change the umbracoUrlAlias property using c# code? I am trying to replace the url with a shorter one if I have a long and complicated url.

    I am using umbraco 7.1.4

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Oct 01, 2014 @ 14:28
    Richard Soeteman
    100

    Hi,

    Can't you use the ContentService events http://our.umbraco.org/documentation/Reference/Events-v6/ContentService-Events? Then set the umbracoUrlAlias property when the normal url is too long?

    Cheers,

    Richard

  • Moran 277 posts 885 karma points
    Oct 02, 2014 @ 11:16
    Moran
    0

    Ok Sounds about right, do I need to place the cs file in the App_Code folder?

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Oct 02, 2014 @ 11:22
    Richard Soeteman
    0

    Yes should be picked up there..

  • Moran 277 posts 885 karma points
    Oct 02, 2014 @ 12:06
    Moran
    0

    Thanks I am trying to debug my class(attach to iis express), but for some reason I get the following message: enter image description here

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Oct 02, 2014 @ 12:44
    Richard Soeteman
    0

    Then the class is not loaded, maybe try starting from Visual studio?

  • Moran 277 posts 885 karma points
    Oct 02, 2014 @ 13:27
    Moran
    0

    I am starting it from VS, visual studio 2012 to be exact :)

  • Moran 277 posts 885 karma points
    Oct 02, 2014 @ 17:16
    Moran
    0

    My bad, I needed to change the web.config for debug... Is there a way to get the node url?

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Oct 02, 2014 @ 17:21
    Richard Soeteman
    0

    umbraco.library.NiceUrl maybe?

  • Moran 277 posts 885 karma points
    Oct 02, 2014 @ 17:28
    Moran
    0

    Thanks

  • Moran 277 posts 885 karma points
    Oct 06, 2014 @ 08:51
    Moran
    0

    I think there is a bug. When I first create the page and publish it the event won't trigger, only after I publish the page for the second time I see the event triggers.

    this is my code

    public class UrlValidationEvent : ApplicationEventHandler
        {
            public UrlValidationEvent()
            {
                ContentService.Publishing += Go;
            }
    
            private void Go(IPublishingStrategy sender, PublishEventArgs<IContent> args)
            {
                foreach (var node in args.PublishedEntities)
                {
                    if (umbraco.library.NiceUrl(node.Id).Length > 38)
                    {
                        string newUrl = node.Name.Replace(" ", "-");
                        node.Properties[9].Value = newUrl;
                    }
                }
            }
        }`
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies