Converts a URL into one that is usable on the requesting client.
Assembly: System.Web (in System.Web.dll)
Occurs if the relativeUrl parameter contains Nothing.
If the relativeUrl parameter contains an absolute URL, the URL is returned unchanged. If the relativeUrl parameter contains a relative URL, that URL is changed to a relative URL that is correct for the current request path, so that the browser can resolve the URL.
For example, consider the following scenario:
A client has requested an ASP.NET page that contains a user control that has an image associated with it.
The ASP.NET page is located at /Store/page1.aspx.
The user control is located at /Store/UserControls/UC1.ascx.
The image file is located at /UserControls/Images/Image1.jpg.
If the user control passes the relative path to the image (that is, /Store/UserControls/Images/Image1.jpg) to the method, the method will return the value /Images/Image1.jpg.
This method uses the TemplateSourceDirectory property to resolve to the absolute URL. The returned URL is for client use.
For more information on resource paths in a Web site, see ASP.NET Web Project Paths.
For mobile Web pages only, if your application relies on cookieless sessions or might receive requests from mobile browsers that require cookieless sessions, using a tilde ("~") in a path can result in inadvertently creating a new session and potentially losing session data. To set a property with a path such as "~/path", resolve the path by calling the ResolveUrl with an argument such as "~/path" before assigning it to the property.
Public Class MyResolveUrl Inherits Control Private _ImageUrl As String Public Property ImageUrl() As String Get Return _ImageUrl End Get Set _ImageUrl = value End Set End Property Protected Overrides Sub Render(output As HtmlTextWriter) Dim myImage As New System.Web.UI.WebControls.Image() ' Resolve Url. myImage.ImageUrl = ResolveUrl(Me.ImageUrl) myImage.RenderControl(output) End Sub End Class
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.