VirtualPathUtility.IsAbsolute(String) 方法

定义

返回一个布尔值,该值指示指定的虚拟路径是否为绝对路径,也就是以正斜杠 (/) 开头。

public:
 static bool IsAbsolute(System::String ^ virtualPath);
public static bool IsAbsolute (string virtualPath);
static member IsAbsolute : string -> bool
Public Shared Function IsAbsolute (virtualPath As String) As Boolean

参数

virtualPath
String

要检查的虚拟路径。

返回

Boolean

如果 virtualPath 是绝对路径,并且不为 true 或空字符串 (""),则为 null;否则为 false

例外

virtualPathnull

示例

下面的代码示例演示如何使用IsAbsoluteIsAppRelativeToAppRelative方法。

StringBuilder sb2 = new StringBuilder();
String pathstring1 = Context.Request.CurrentExecutionFilePath.ToString();
sb2.Append("Current Executing File Path = " + pathstring1.ToString() + "<br />");
sb2.Append("Is Absolute = " + VirtualPathUtility.IsAbsolute(pathstring1).ToString() + "<br />");
sb2.Append("Is AppRelative = " + VirtualPathUtility.IsAppRelative(pathstring1).ToString() + "<br />");
sb2.Append("Make AppRelative = " + VirtualPathUtility.ToAppRelative(pathstring1).ToString() + "<br />");
Response.Write(sb2.ToString());
Dim sb2 As New StringBuilder()
Dim pathstring1 As String = Context.Request.CurrentExecutionFilePath.ToString()
sb2.Append("Current Executing File Path = " & pathstring1.ToString() & "<br />")
sb2.Append("Is Absolute = " & VirtualPathUtility.IsAbsolute(pathstring1).ToString() & "<br />")
sb2.Append("Is AppRelative = " & VirtualPathUtility.IsAppRelative(pathstring1).ToString() & "<br />")
sb2.Append("Make AppRelative = " & VirtualPathUtility.ToAppRelative(pathstring1).ToString() & "<br />")
Response.Write(sb2.ToString())

注解

如果虚拟路径以文本斜杠 (/) 开头,则为绝对路径。 例如,该 Path 属性返回绝对虚拟路径。

适用于

另请参阅