VirtualPathUtility.IsAppRelative(String) 方法

定义

返回一个布尔值,该值指示指定的虚拟路径是否相对于应用程序。

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

参数

virtualPath
String

要检查的虚拟路径。

返回

如果 virtualPath 相对于应用程序,则 true;否则,false

例外

virtualPath null

示例

下面的代码示例演示如何使用 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())

注解

虚拟路径可以是根运算符(波形符 [~]),也可以以根运算符开头。 如果 virtualPathnull,则会引发 ArgumentNullException 异常。 如果 virtualPath 为空字符串(“),则 IsAppRelative 方法返回 false

注意

"~ filename " 不是有效的虚拟路径,返回 IsAppRelative 方法的 false

适用于

另请参阅