Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Referring URL on 404 page View modes: 
User avatar
Member
Member
Rene 7 - 8/19/2012 6:42:12 PM
   
Referring URL on 404 page
Dear Kenitco,
we are restructuring our site and therefore many links in the copy will be broken. We are developing a webpart that sits on the 404 page. It makes suggestions where to go depending on the error path. It also should send an email to webmaster which link is broken together with the referring URL (The URL of the page where the broken link sits on.)
I tried a few:
CMSContext.CurrentUser.URLReferrer.ToString();
Request.ServerVariables["http_referer"].ToString();
Request.UrlReferrer.LocalPath.ToString();

These return the broken page (error path) which is correctly the referring URL. But I would like to go one more step back to get the page with the actual broken link. Is this possible?

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/20/2012 12:05:22 AM
   
RE:Referring URL on 404 page
Maybe try Page.PreviousPage.Request.UrlReferrer
Check to make sure all of those things aren't null.

User avatar
Member
Member
Rene 7 - 8/20/2012 1:32:05 AM
   
RE:Referring URL on 404 page
Hi Jiveabillion,
Handling "Page" seems to be tricky, could you please give a code example?

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/20/2012 2:14:54 AM
   
RE:Referring URL on 404 page
'Page' should be available as a property of a any page or user control you make.

if(this.Page.PreviousPage !=null)
{
if(this.Page.Request.UrlReferrer !=null)
{
string referrer = this.Page.Request.UrlReferrer.ToString();
}
}


The reason you should use PreviousPage is because the 404 page shouldn't be the original page the user went to. Sometimes it isn't available though, mostly when you're trying to access it on the first page the user visited when their session was created.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/20/2012 8:27:47 AM
   
RE:Referring URL on 404 page
Hello,


You can use the RequestStockHelper class to save a referer of current URL for your custom key when the request begins (see: Global events). Then you can get the value for your purpose on the error page. Please note that this can work even if there is no redirection before you display the error page (it works only with URL rewriting).

More information about RequestStockHelper is in our API Reference.


Best regards,
Helena Grulichova