开发者

asp.net After a Server.Transfer how do you get the path of the current page?

To get the url of the current page, I usually do something like this:

s开发者_如何学Pythontring path = Request.Path;

If I do this after a Server.Transfer then I get the path of the page where the transfer was done. How can I get it for the current page?

For example:

On Page1.aspx I do Server.Transfer ("Page2.aspx")

On Page2.aspx Request.Path returns /Page1.aspx and not /Page2.aspx

I would like to get /Page2.aspx. How can I get it?


You're looking for the Request.CurrentExecutionFilePath property.


AppRelativeVirtualPath (http://msdn.microsoft.com/en-us/library/system.web.ui.templatecontrol.apprelativevirtualpath.aspx) seems to do the trick.


When you use Server.Transfer, despite the URL on browser doesn't change, the Request references URL does. So, you may use the UrlReferrer property's Request. UrlReferrer gets information about the URL of the client's previous request that linked to the current URL.

For instance

string myContextBrowserPath = Context.Request.UrlReferrer.AbsolutePath
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜