Hi
I am having an issue with long urls, like this post. I am trying to implement a solution which will replace the long url with the umbracoUrlAlias property an will use it for the page url.
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;
}
}
}
}
When I save and publish the page for the first time the event won't trigger and the method doesn't run, it's only when I save and publish the page for the second time the event is triggered.
Hi Moran.
I assume you are using a 6 or above version.
My thought is that you are tackling this the wrong way.
You should implement your own custom IUrlProvider and then register it within The UrlProviderResolver on application starting event.
I suggest you inherit from DefaulUrlProvider rather then write your own full implementation.
Unfortunately I am not near my desktop. So I cannot send you an example.
Publish event won't trigger
Hi I am having an issue with long urls, like this post. I am trying to implement a solution which will replace the long url with the umbracoUrlAlias property an will use it for the page url.
this is my code:
When I save and publish the page for the first time the event won't trigger and the method doesn't run, it's only when I save and publish the page for the second time the event is triggered.
any thoughts?
Hi Moran. I assume you are using a 6 or above version.
My thought is that you are tackling this the wrong way.
You should implement your own custom IUrlProvider and then register it within The UrlProviderResolver on application starting event. I suggest you inherit from DefaulUrlProvider rather then write your own full implementation. Unfortunately I am not near my desktop. So I cannot send you an example.
Hi Moran,
Doron is right. You can solve this without the publish event like he said.
You can find some implementation examples in the Hybrid Framework : https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/tree/master/Umbraco.Extensions/UrlProvider
Dave
Great thanks :) I will try and report back :)
Hi Dave Do I need to reference "Umbraco.Extensions" so I can use this code samples?
This is my test code:
and this is the error message I get (stack trace)
I am using umbraco 7.1.4
Hi Moran,
One thing that jumped right into my view is, though I am not sure it explains this error, is the following line:
content.Url is what the UrlProvider tries to resolve, so I don't think you should be calling it.
What I would do is instead of directly implementing IUrlProvider, inherit from DefaultUrlProvider, override the GetUrl , and do something like this
Another thing I've noticed is that you do not return anything within the if statement.
is working on a reply...