How do I identify the referrer page in ASP.NET?

dotnet-practitioner picture dotnet-practitioner · Apr 12, 2010 · Viewed 28.6k times · Source

In VS2003, I am trying to find out the particular page where the request is coming from. I want to identify the exact aspx page name.

Is there a way to only get the page name or some how strip the page name?

Currently I am using the following instruction...

string referencepage = HttpContext.Current.Request.UrlReferrer.ToString();

and I get the following result...

"http://localhost/MyPage123.aspx?myval1=3333&myval2=4444;

I want to get the result back with out any query string parameters and be able to identify the page MyPage123.aspx accurately...

How do I do that??

Answer

Matti Virkkunen picture Matti Virkkunen · Apr 12, 2010

Instead of calling .ToString on the Uri, use the AbsolutePath property instead:

string referencepage = HttpContext.Current.Request.UrlReferrer.AbsolutePath;

This should get you "/MyPage123.aspx" in your case.

Edit: Had LocalPath instead of AbsolutePath by mistake