Developer forum

Forum » CMS - Standard features » Create 301 redirects for deleted pages after import

Create 301 redirects for deleted pages after import

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a DW8 solution where I have a scheduled task importing ItemType pages. The task is set to delete pages that are not in the source anymore.

Obviously, if those pages are indexed by Google, they will start returning 404 errors.

Which is why I have to create DirectPath records for them.

So far I have tried using Dynamicweb.Notifications.Integration.JobFinished notification where ideally, I would need to get the friendy url for each deleted page (availabe in the args of the notification).

I have defined a list of type "Page" and for each page I try to generate the friendy url.

     foreach (Page crtPage in listOfPages)
{
crtPage.ExactUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(crtPage.ID);
crtPage.Save();
}

I need the friendy url to save it in UrlPath path table.

When I call GetFriendlyUrl the response is :

System.NullReferenceException: Object reference not set to an instance of an object.
 at Dynamicweb.Frontend.PageView.SetID()
 at Dynamicweb.Frontend.PageView.Load()
 at Dynamicweb.Frontend.PageView.GetPageviewByPageID(Int32 PageID, IDictionary values, Boolean useCache)
 at Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(Int32 pageID)
 
 
 My questions are:

1. Can I create a DirectPath record using the Unfriendly URL? Something like /Default.aspx?ID={PageID}
2. If #1 is not possible, how/where can I call GetFriendlyUrl in the notification? My asumption is that I am using the wrong method
3. If the friendy URL is not available since the page was already deleted, if I query TrashBin would I be able to get the ExactURL property of the deleted pages? Asuming I would save the Friendly URL after import.

Thank you,
Adrian


Replies

 

You must be logged in to post in the forum