Sitecore saveUI processor redirecting to item page

2019-07-21 21:24发布

问题:

I have implemented a Sitecore saveUI processor for moving news items to a specific location inside a year/month hierarchical structure. It does the job well, except for the fact that when used inside the Page Editor (navigating to an item's page and then trying to save, and implicitly move, the item) I am redirected to our 404 page, since Sitecore expects the original item's url to still be valid after the operation.
Is there any way to tell Sitecore that the item has been moved? I'm thinking at some property in SaveArgs, but any solution would do, as long as it's somewhat maintainable (for example, I'd prefer a server-side solution, not a client-side JavaScript-based one, if possible).

回答1:

Off the top of my head, make sure your processor the last one in the pipeline and add the following code to the end of the process method:

if(Sitecore.Context.PageMode.IsPageEditor)
{
    var item = args.SavedItems.First() // or perhaps Context.Item;
    var url = LinkManager.GetItemUrl(item);
    HttpContext.Current.Response.Redirect(url);
}


回答2:

Have you tried using the Sitecore Newsmover Module? This works seamlessly and could be the way to go instead of creating custom movers. We have used this plenty of times and it does seem to work well in all conditions.

Sample config for this:

    <template id="User Defined/News Article" sort="Descending">
      <DateField>Posted Date</DateField>
      <YearTemplate formatString="yyyy">User Defined/Folders/Article Year Folder</YearTemplate>
      <MonthTemplate formatString="MMMM">User Defined/Folders/Article Month Folder</MonthTemplate>
    </template>