Copied to clipboard

Flag this post as spam?

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


  • Moran 285 posts 934 karma points
    Oct 19, 2014 @ 09:20
    Moran
    0

    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:

    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.

    any thoughts?

  • Doron Uziel 23 posts 93 karma points
    Oct 19, 2014 @ 12:45
    Doron Uziel
    0

    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.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 19, 2014 @ 13:18
    Dave Woestenborghs
    0

    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

  • Moran 285 posts 934 karma points
    Oct 19, 2014 @ 13:24
    Moran
    0

    Great thanks :) I will try and report back :)

  • Moran 285 posts 934 karma points
    Oct 26, 2014 @ 13:01
    Moran
    0

    Hi Dave Do I need to reference "Umbraco.Extensions" so I can use this code samples?

  • Moran 285 posts 934 karma points
    Oct 26, 2014 @ 14:17
    Moran
    0

    This is my test code:

     public class UrlHelper : BaseClass, IUrlProvider
        {
            public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
            {
                return Enumerable.Empty<string>();
            }
    
            public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
            {
                var content = umbracoContext.ContentCache.GetById(id);
                if (content.Url.Length > 38)
                {
                    string newUrl = content.Url.Replace(" ", "-");
                    //content.Properties.Select(item => item.)
                }
                return null;
            }
        }
    

    and this is the error message I get (stack trace)

    [ReflectionTypeLoadException: Could not load types from assembly Umbraco.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, errors:
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    ]
       Umbraco.Core.TypeFinder.GetTypesWithFormattedException(Assembly a) +383
       Umbraco.Core.TypeFinder.GetClasses(Type assignTypeFrom, IEnumerable`1 assemblies, Boolean onlyConcreteClasses, Func`2 additionalFilter) +332
       Umbraco.Core.TypeFinder.GetClasses(Type assignTypeFrom, IEnumerable`1 assemblies, Boolean onlyConcreteClasses, Func`2 additionalFilter) +925
       Umbraco.Core.TypeFinder.FindClassesOfType(IEnumerable`1 assemblies, Boolean onlyConcreteClasses) +62
       Umbraco.Core.TypeFinder.FindClassesOfType(IEnumerable`1 assemblies) +45
       Umbraco.Core.<>c__DisplayClass41`1.<ResolveTypes>b__40() +60
       Umbraco.Core.PluginManager.LoadViaScanningAndUpdateCacheFile(TypeList typeList, TypeResolutionKind resolutionKind, Func`1 finder) +46
       Umbraco.Core.PluginManager.ResolveTypes(Func`1 finder, TypeResolutionKind resolutionType, Boolean cacheResult) +2254
       Umbraco.Core.PluginManager.ResolveTypes(Boolean cacheResult, IEnumerable`1 specificAssemblies) +149
       Umbraco.Core.CoreBootManager.InitializeApplicationEventsResolver() +46
       Umbraco.Web.WebBootManager.InitializeApplicationEventsResolver() +5
       Umbraco.Core.CoreBootManager.Initialize() +257
       Umbraco.Web.WebBootManager.Initialize() +18
       Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e) +89
       Umbraco.Core.UmbracoApplicationBase.Application_Start(Object sender, EventArgs e) +9
    
    [HttpException (0x80004005): Could not load types from assembly Umbraco.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, errors:
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    ]
       System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9916613
       System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
       System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
       System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
       System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
    
    [HttpException (0x80004005): Could not load types from assembly Umbraco.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, errors:
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    Exception: System.TypeLoadException: Could not load type 'Umbraco.Core.PropertyEditors.IPropertyValueConverterMeta' from assembly 'Umbraco.Core, Version=1.0.5261.28127, Culture=neutral, PublicKeyToken=null'.
    ]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930508
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
    

    I am using umbraco 7.1.4

  • Doron Uziel 23 posts 93 karma points
    Oct 26, 2014 @ 15:10
    Doron Uziel
    0

    Hi Moran,

    One thing that jumped right into my view is, though I am not sure it explains this error, is the following line:

    string newUrl = content.Url.Replace(" ","-");

    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

    string defaultUrl= base.GetUrl(umbracoContext,id,current,mode); if(defaultUrl.Length>38){...}

    Another thing I've noticed is that you do not return anything within the if statement.

     

Please Sign in or register to post replies

Write your reply to:

Draft