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.aspxI 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
精彩评论