开发者

ASP.NET: IsVirtualPath?

Is there a function to开发者_JAVA技巧 determine whether a URI is a valid virtual path? I'm given a string and need to use Server.MapPath() on it without throwing an Exception when the string is not a valid virtual path.

Vote to close my question. Answer is @ asp.net - Is my path virtual?.


You could use the File.Exists() and Directory.Exists() methods to check the output of Server.MapPath() and verify that a file/directory exists at the specified path.

Dim myPath as String = Server.MapPath('/some/path.aspx')
If File.Exists(myPath) Then
    //Do Something
Else
   If Directory.Exists(myPath) Then
       //Do Something
   Else
       //Invalid path
   End If
End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜