Control.ResolveUrl vs Control.ResolveClientUrl vs VirtualPathUtility.ToAbsolute

Is there any advantage to using one of these methods over the other when resolving paths starting with a tilde (~)?

Generally, what is better if you send relative paths or absolute paths down to your html?

+24
Feb 05 '09 at 22:09
source share
4 answers

The difference between ResolveUrl and ResolveClientUrl is that ResolveClientUrl returns the path relative to the current page, ResolveUrl returns the path relative to the site root:

http://www.andornot.com/blog/post/ResolveUrl-vs-ResolveClientUrl.aspx

I would recommend using absolute paths.

Edit : Rick Stryle posted a good article about it

Edit2 : removed caching bit. Does not add an answer and may not necessarily be accurate.

http://west-wind.com/weblog/posts/132081.aspx

+24
Apr 22 '09 at 16:41
source share

Here's another article explaining the difference between the different ways to solve paths in ASP.NET -

Different approaches to resolving URLs in ASP.NET

+5
Sep 04 '09 at 19:18
source share

Note that VirtualPathUtility.ToAbsolute (virtualPath) throws an exception if the query string is included in the path.

An HttpException message will in turn "~ / YourVirtualPath / YourPage.aspx? YourQueryStringArg = FooBar" is not a valid virtual path.

See Rick Strahl Web Log: ResolveUrl () without page and MSDN: VirtualPathUtility.ToAbsolute Method (String)

+4
Apr 13 2018-10-10T00:
source share

Another difference I noticed:

The code:

string value = "~/Docs/Hello & World.aspx"; Response.Write(HyperLink1.ResolveClientUrl(value) + "<br/>"); Response.Write(HyperLink1.ResolveUrl(value) + "<br/>");

Result:

Documents / Hello% 20 &% 20World.aspx

/ Docs / Hello and World.aspx

+1
Mar 08 2018-11-11T00:
source share



All Articles