BVN.404Handler map redirect values automatically

Vote:
 

I am using a scheduled job that moves outdated events to a folder called "Past events". After the event have been moved, I want to change the events page url from its old one to the new so it matches the hierarchy of its new location. For this, I am using a custom redirect gadget called BVN.404Handler.

if(Configuration.Logging == LoggerMode.On && Upgrader.Valid)
        {
            Logger.LogRequest(urlNotFound, referer);
        }

The line of code above only logs a suggestion of the old url and the new one. Since this is a scheduled job that moves pages based on their endDate value i need to make the redirect gadget register the url mappings automatically. With the current solution, a user needs to manually open the gadget and confirm the mapping by pasting the newurl (known referrers) value into the textfield and pressing "Add".

This is what it looks like:

Redirect gadget

Is this possible to achieve with the current version of this gadget?

  

Or do anyone know a possible workaround for achieving this?

Thanks in advance

#122604
Jun 06, 2015 11:59
Vote:
 

Hi,

Maybe inside you Scheduled Job execute method you could use something like (I didn't test it):

IEnumerable<PageData> pagesToMove = LoadAllOutdatedEvents();
            
// save old URLs
var oldUrls = new Dictionary<int, string>();
            foreach (var pageData in pagesToMove)
            {
                oldUrls[pageData.PageLink.ID] = pageData.LinkURL;
            }

// job -  moves outdated events (your current code)
// ....
// ...            


// save redirects
            var customRedirectCollection = CustomRedirectHandler.Current.CustomRedirects;

            foreach (var pageData in pagesToMove)
            {
                var pageWithNewUrl = contentRepository.Get<PageData>(pageData.PageLink.ToReferenceWithoutVersion());
                customRedirectCollection.Add(new CustomRedirect(  oldUrls[pageData.PageLink.ID], pageWithNewUrl.LinkURL  ));
            }
            CustomRedirectHandler.Current.SaveCustomRedirects(customRedirectCollection);
#122607
Jun 07, 2015 0:00
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.