我需要在经典的asp代码中创建asp.net的副本。请建议

时间:2012-08-02 13:00:30

标签: asp-classic

我需要以下asp.net代码的经典asp代码。

asp.net-System.Environment.MachineName

asp.net-使用Server.Mappath

1 个答案:

答案 0 :(得分:2)

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非常容易。

相关问题