views:

137

answers:

2

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??

A: 

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

Matti Virkkunen
+1  A: 

Look at the Segments property of the URI class (which is what HttpContext.Current.Request.UrlReferrer returns).

Something like HttpContext.Current.Request.UrlReferrer.Segments[1] (changing the 1 indexer to get the correct segment you require).

Dan Diplo
This is the way to go if you want only the filename, without any directories. Be careful if you use directories and might have a file with the same name in multiple directories.
Matti Virkkunen