How to convert Relative URL to Absolute URL in ASP.NET page

by rezashirazi 11/12/2008 3:59:00 PM
Very often we have a relative URL of some page or resource like "~/img/logo.gif" and we need an absolute URL
to insert it in some control or link (something like "http://www.rezashirazi.com/img/logo.gif")

Asp.Net 2.0 has some very useful methods that could help us to resolve the absolute URL we need.

First of them is Page method ResolveUrl() that converts a relative URL into one that is usable on the requesting client.
This means you we can pass to this method an URL that is relative to the current page, something like this:


        Page.ResolveUrl("img/logo.gif");
 

and it would return to us a valid relative URL , taking into account the current URL of the Page from where you are calling it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ASP.NET

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

7/4/2009 3:21:52 AM

About the author

Name of author Reza Shirazi Mofrad
Interests: Image processing, computer vision, Artificial intelligence, Microsoft .NET technologies, Web programming.

E-mail me Send mail

Calendar

<<  July 2009  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

Site statistics

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in