Last post Nov 04, 2009 08:35 AM by Babunareshnarra
Nov 04, 2009 07:17 AM|John Federer|LINK
Can any one tell me the purpose of using Page.ResolveUrl
Nov 04, 2009 08:08 AM|XIII|LINK
taken from MSDN (http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx):
Converts a URL into one that is usable on the requesting client.
Before you ask that this method is from the Control class take into account that the Page class inherits itself from Control in the end.
Nov 04, 2009 08:11 AM|irokhes|LINK
Page.ResolveUrl to always return its URLs as an app-absolute path.
Resolve URL always gives you the root of virtual directory.
e.g. if you say ResolveURL("~/default.aspx");
then it gives you path "Web/Default.aspx". where web is path of your virtual directory.
Nov 04, 2009 08:35 AM|Babunareshnarra|LINK
If, from an ASP.NET page, you need to access or refer to a file that resides in a different directory, you have a number of options to refer to that file. You can use an absolute path, such as
The problem with either of these approaches is that they are sensitive to changes in the site's layout or configuration. With absolute paths you can run into difficulties if you use different base application directories for development and production (i.e.,
using a virtual directory as the application root in a development server, but hosting the live version of the site in the root directory of the website). With relative paths things can go haywire if the ASP.NET page that references the file is moved to another
A workaround for this is to use the
Returns the correct path based on the application's root. For example, if the application was rooted at the virtual directory Foo, the return value would be /Foo/Images/Skyline.jpg...'VB.NET... Dim url as String = Page.ResolveUrl("~/Images/Skyline.jpg")// C#... string url = Page.ResolveUrl(@"~/Images/Skyline.jpg");
(Thanks to Phil Winstanley for this suggestion!) from http://4guysfromrolla.com/articles/052505-1.aspx
Hope this helps.