【发布时间】:2021-07-23 10:54:06
【问题描述】:
我使用函数来获取根文件夹路径,并启动我的 ASP.NET 应用程序的代码。 但没有工作,它显示错误“长度不能小于零” 以下是我的代码,有人可以给我建议吗?谢谢
Private Function FindDir(ByVal path As String) As String
Dim url As String = Request.ServerVariables("SCRIPT_NAME")
Dim initialSlash As Integer = 0
Dim CurrentSlash As Integer = 0
Dim myRootPath As String = Nothing
initialSlash = url.LastIndexOf("/")
myRootPath = url.Substring(0, initialSlash)
CurrentSlash = myRootPath.LastIndexOf("/")
Do While CurrentSlash <> initialSlash And CurrentSlash <> 0
myRootPath = myRootPath.Substring(0, CurrentSlash)
CurrentSlash = myRootPath.LastIndexOf("/")
Loop
myRootPath = myRootPath.Substring(1)
Return myRootPath
End Function
【问题讨论】:
-
当你可以通过
Dim url As String = Request.ApplicationPath得到它时,你为什么要做这一切。 -
您好@G3nt_m3caj,感谢您的评论和建议。让我了解有关 Request.ApplicationPath 的更多信息。