This project is read-only.

How to see value changes on save

Topics: Troubleshooting
Oct 2, 2012 at 12:56 PM
Edited Oct 2, 2012 at 1:39 PM



I'm writing a redirect module where I need to see if the Path of a ContentItem/RoutePart has been changed. But I can't find how exactly to do this. My best guess is that I should do this in the Handler. But the methods I can use are a bit confusing and so is the context. For example:

 protected override void Unpublishing(PublishContentContext context)
      var current = context.ContentItem.As<RoutePart>();
      var result = context.PreviousItemVersionRecord.As<RoutePart>();      
      var previous = result.As<RoutePart>();

      if (current.Path != previous.Path)
        // Do stuff      


What I'm trying to do here is find the path of the previous version and compare it to the current. But since the previous item is a VersionRecord it does not have the "As<>" method from which I can retrieve the routepart.

What am I missing?

Oct 3, 2012 at 11:01 AM

Pointers anyone?

Oct 3, 2012 at 5:40 PM

Take a look at DefaultContentManager.GetAllVersions.

Oct 4, 2012 at 7:40 AM

What I've ended up doing is comparing the slug with the path. The slug is the posted value and the path is the previous slug. Although I'd expect to compare te previous version with the current version. Which I got working using GetAllVersions (but ended up not using ;) . I'm not familiar with Orchard's inner workings but it seems wrong to simply scoop up all versions of a ContentItem just to get the previous one.