我需要以下 asp.net 代码的经典 asp 代码。
asp.net-System.Environment.MachineName
asp.net-Server.MapPath
最佳答案
ASP Server.MapPath 不支持像 ASP.NET 版本那样解析 URL 开头的“~/”。这是我去年在这里发布的代码:
Function UrlContent(sUrl)
If InStr(1, sUrl, "~/") = 1 Then
UrlContent = ApplicationPath & Mid(sUrl, 2)
Else
UrlContent = sUrl
End If
End Function
Function ApplicationPath()
Dim pos: pos = Len(Request.ServerVariables("INSTANCE_META_PATH")) + 6
ApplicationPath = Mid(Request.ServerVariables("APPL_MD_PATH"), pos)
End Function
UriContent
获取传入的 URL 并解析“~/”以返回相对于主机网站的 URL。因此,与 ASP.NET 代码等效的 MapPath 是:
Dim physicalPath : physicalPath = Server.MapPath(UrlContent(virtualPath))
获取计算机名称要困难得多,因为您需要访问 Windows API。名为“SERVER_NAME”的服务器变量只是请求中使用的主机名,因此它与实际的 Windows 计算机名称不同。
创建允许脚本访问环境的 .NET COM Interop dll 相当容易。
关于asp-classic - 我需要用经典的 asp 代码创建 asp.net 的副本。请建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11777972/