It depends on what is the actual purpose - as many things can happen from the user request to the acual servicing of the request, you might want to use Request.PhysicalPath, you might also want to use the CurrentExecutionFilePath (this will take Server.Transfer
etc into account).
You might also be interested in the actual request (after rewrite), and use Request.Url.AbsolutePath .
Finally (?) if you want the unmodified original use new Uri(Request.RawUrl).Absolute.Path.
In cases where a physical path is involved, use System.IO.Path.GetFileName() and System.IO.Path.GetExtension() methods to extract parts of it, and use System.Web.VirtualPathUtility.GetFileName() and GetExtension() methjods when it's a part of an URL or is
a virtual path.
Why can't things just be simple? ;-)
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
Marked as answer by TATWORTH on Apr 06, 2010 11:58 AM
Svante
All-Star
18347 Points
2300 Posts
Re: How to get current page file name?
Dec 17, 2007 07:00 AM|LINK
It depends on what is the actual purpose - as many things can happen from the user request to the acual servicing of the request, you might want to use Request.PhysicalPath, you might also want to use the CurrentExecutionFilePath (this will take Server.Transfer etc into account).
You might also be interested in the actual request (after rewrite), and use Request.Url.AbsolutePath .
Finally (?) if you want the unmodified original use new Uri(Request.RawUrl).Absolute.Path.
In cases where a physical path is involved, use System.IO.Path.GetFileName() and System.IO.Path.GetExtension() methods to extract parts of it, and use System.Web.VirtualPathUtility.GetFileName() and GetExtension() methjods when it's a part of an URL or is a virtual path.
Why can't things just be simple? ;-)
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.