asp-classic - 我需要用经典的 asp 代码创建 asp.net 的副本。请建议

标签 asp-classic

我需要以下 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/

相关文章:

iis - Vista 的 IIS 实例没有 SMTP(解决方案?)

file-upload - ASP VB上传文件,不要使用原来的文件名!使用 URL 方案来命名上传的文件。

python - ASP 脚本中 Python 的 500 服务器错误

javascript - 客户端 <script> 标记中服务器端经典 ASP 代码的问题

iis - 如何在 IIS 7 上的经典 ASP 中启用大文件上传?

amazon-web-services - 在 AWS 负载均衡环境中使用经典 ASP session 变量是否有技巧?

asp.net - 如何区分 ASP 和 ASP.NET 代码/网站文件

html - 在浏览器中查看扩展名为 .asp 的本地 html 文件

asp-classic - 经典 ASP 显示变量

javascript - Google Maps Address 而不是 LatLng GeoCode