ASP.NET:是虚拟路径吗?

发布于 2024-08-12 00:23:27 字数 236 浏览 4 评论 0原文

是否有函数可以判断 URI 是否为有效的虚拟路径?我得到了一个字符串,当该字符串不是有效的虚拟路径时,需要对其使用 Server.MapPath() 而不抛出异常。

投票结束我的问题。答案是@ asp.net - 我的路径是虚拟的吗?

Is there a function to 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?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2024-08-19 00:23:27

您可以使用 File.Exists() 和 Directory.Exists() 方法检查 Server.MapPath() 的输出并验证文件/目录是否存在于指定路径。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文