Click here to Skip to main content
Licence CPOL
First Posted 16 Sep 2011
Views 6,071
Bookmarked 3 times

whats the difference in Page class function ResolveURL vs ResolveClientURL

The .NET Page class contains two methods ResolveUrl and ResolveClientUrl  which are at first glance looks same.They both took same relative url and returns browser friendly URl. So why 2 function to do the same job? Though their functionality is same but their way of returning client brower relative
A Technical Blog article. View original blog here.[^]

The .NET Page class contains two methods ResolveUrl and ResolveClientUrl  which are at first glance looks same. They both took same relative URL and returns browser friendly URl. So why 2 function to do the same job? Though their functionality is same but their way of returning client brower relative url makes the huge difference.ResolveClientUrl returns a path relative to the current page which user currently browsing, and ResolveUrl returns a path relative to the site root that is configured as root in IIS. 

Lets Consider this structure:
ROOT
–App_Themes
–Images
—-mypic.png
–MyAccount
—-default.aspx 

Now from above example root of the IIS directory is ROOT, and all other directory is under this root. Now from MyAccount->default.aspx tries to access Images->mypic.png. ResolveUrl will do top to bottom parsing to find the resource, on other hand ResolveClientUrl will do bottom up parsing to find the same resource.

Function: Page.ResolveUrl("~/Images/mypic.png") 
Returns: "/Images/mypic.png" 
Function: Page.ResolveClientUrl("~/Images/mypic.png")
Returns: "../Images/mypic.png" 

Difference betwwen this two is very visible if you hoste your web app under a shared hosting under a subdomain. For example you host your MY_SITE app under www.example.com subdomain, and your physical file path is

example.com\www\MY_SITE under IIS directory. So under this you placed your file structure given above. Now for any link if you set

Page.ResolveUrl("~/MyAccount/default.aspx"), 

watch out the URL in browser status bar you will see www.example.comwww/MY_SITE/MyAccount/default.aspx, because ResolveUrl will parse from top root domain for this resource, so it took full path from root for that specific resource. On other hand ResolveClientUrl can solve this problem, this will parse from browsers present location to up towards the root so find the specific resource path.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Shahriar Iqbal Chowdhury

Technical Lead

Bangladesh Bangladesh

Member

Shahriar Iqbal Chowdhury is a Software Engineer working on Microsoft .NET Technology.He is responsible for developing several web/desktop application build on .NET technology which are running successfully on USA,Germany,Netherlands.His point of interest is Design Pattern.
 
web: http://www.imgalib.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 16 Sep 2011
Article Copyright 2011 by Shahriar Iqbal Chowdhury
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid