Take the 2-minute tour ×

I find myself using the ResolveUrl function a lot in my aspx pages but the resolved path is always relative. i would like to be able to have the rendered path start with the regular "http://localhost/myproject/"

How can i achieve that without breaking any code in case i change the hierarchy of my files? Would it be inefficient to write a function and call it for every targeted link on the page?

share|improve this question

2 Answers 2

up vote -1 down vote accepted

Never mind guys, I found some code online from a Rick Strahl post and it seems to be something i might use in my case! thanks for the help

share|improve this answer

Use the ~ when you resolve the url. It will always go to the application root.



will resolve to...


You will need to manually add the server address:

Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port

A sample function would be

string ResolveAbsoluteUrl(string path)
    return Request.Url.Scheme + "://" + Request.Url.Host + ":" + Request.Url.Port + ResolveUrl(path);
share|improve this answer
ok, but is there a function to get the 'localhost ..' part added to it too? –  ak3nat0n Apr 18 '09 at 21:36

Your Answer


