将 URL 转换为在请求客户端可用的 URL。
[Visual Basic] Public Function ResolveUrl( _ ByVal relativeUrl As String _ ) As String [C#] public string ResolveUrl( string relativeUrl ); [C++] public: String* ResolveUrl( String* relativeUrl ); [JScript] public function ResolveUrl( relativeUrl : String ) : String;转换后的 URL。
如果 relativeUrl 参数包含绝对 URL,则该 URL 原样返回。如果 relativeUrl 参数包含相对 URL,则该 URL 将更改为与当前请求路径相符的相对 URL,这样浏览器便能够解析该 URL。
例如,请考虑以下方案:
客户端已请求了一个 ASP.NET 页,该页含有一个用户控件,该用户控件有一个关联的图像。 ASP.NET 页位于 /Store/page1.aspx。 用户控件位于 /Store/UserControls/UC1.ascx。 图像文件位于 /UserControls/Images/MyPhoto1.jpg。如果用户控件将图像的相对路径(即 /Store/UserControls/Images/MyPhoto1.jpg)传递给 ResolveUrl 方法,则该方法将返回值 /UserControls/Images/MyPhoto1.jpg。
此方法使用 TemplateSourceDirectory 属性解析为绝对 URL。返回的 URL 适用于客户端。
[Visual Basic, C#, C++] 下面的示例创建一个 Image Web 服务器控件对象,并使用 ResolveUrl 方法设置该图像的路径(该路径由 ImageUrl 属性存储)。
[Visual Basic] ' Use the Context property to write text to the Response object ' associated with the current request. Context.Response.Write("<br><br>ParentControl's OnBubbleEvent called.") Context.Response.Write(("<br>Source of event is: " + sender.ToString())) [C#] // Use the Context property to write text to the Response object // associated with the current request. Context.Response.Write("<br><br>ParentControl's OnBubbleEvent called."); Context.Response.Write("<br>Source of event is: " + sender.ToString()); [C++] // Use the Context property to write text to the Response Object* // associated with the current request. Context->Response->Write(S"<br><br>ParentControl's OnBubbleEvent called."); Context->Response->Write(String::Concat(S"<br>Source of event is: ", sender));[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮 。
平台: Windows 2000, Windows XP Professional, Windows Server 2003 系列