开发者

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

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 f开发者_StackOverflowollowing 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??


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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜