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 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;
}
}
}
}`
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
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
Ok Sounds about right, do I need to place the cs file in the App_Code folder?
Yes should be picked up there..
Thanks I am trying to debug my class(attach to iis express), but for some reason I get the following message:
Then the class is not loaded, maybe try starting from Visual studio?
I am starting it from VS, visual studio 2012 to be exact :)
My bad, I needed to change the web.config for debug... Is there a way to get the node url?
umbraco.library.NiceUrl maybe?
Thanks
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
is working on a reply...