SharePoint Custom Router Redirect Issue

An odd one this.

I created a custom router within an premise SharePoint 2019 environment, this custom router was designed to move documents from a drop off library to a site which is programatically selected based on a provided managed metadata field custom property value – also added logging to a central SharePoint list. This was all relatively straight forward, and reasonably well documented – Custom Routers however are not documented well at all.

However, after I had configured all this and began testing the router on documents within my drop off library, the OK button on the success.aspx page (which is navigated to when using a custom router which uses the CustomRouterResult.SuccessCancelFurtherProcessing result) appended the current relative url path (held within the NextUrl parameter) to the drop off library url location – thus taking me to a lovely 404 error page.

An example of this broken URL is: http://webapp/managedpath/sitename/managedpath/sitename/DropOffLibrary

When trying to find a solution for this, I tried all sorts of setting values within the custom router code – but to no success unfortunately.

So how did I resolve this? Well it is a rather hacky solution, however with no other viable options I took it happily.

  1. Find the success.aspx page within the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\TEMPLATE\LAYOUTS location
  2. Take a copy of the file (in case you want to revert later on)
  3. Edit the success.aspx file in notepad or similar
  4. Below the second table element – but above </asp:Content>, copy the following code:
<script type="text/javascript">
document.getElementById("ctl00_PlaceHolderMain_ctl00_RptControls_BtnSuccessOK").onclick = function() {
    var pageUrl = window.location.search(substring(1);
    var urlParams = pageUrl.split('&');
    var destination = "";
    for(var i = 0; i < urlParams.length; i++)
    {
        var urlParamName = urlParams\[i].split('=');
        if(urlParamName\[0] == "NextUrl")
        {
            destination = urlParamName\[1];
            break;
        }
    }
    window.location.href = "/" + destination;
}
  1. Save the success.aspx page and retry the OK button – it should now work as expected