Server.MapPath()奇怪的问题

时间:2014-05-02 18:14:07

标签: asp-classic iis-6

是否有人观察或处理过以下问题。我有几个运行Windows 2003,IIS 6的Web服务器(Dev,QA,Staging)。 最近应用了一个使用以下代码行的更新:

sLogPath = Server.MapPath("../Templates/" & strFileName)        
set fs = Server.CreateObject("Scripting.FileSystemObject")       
If fs.FileExists(sLogPath) Then

在所有开发系统上都可以正常工作,但只要我们将其移至QA,我就会收到错误:

The '..' characters are not allowed in the Path parameter for the MapPath method.
Line number xxx 

行号是这一行

sLogPath = Server.MapPath("../Templates/" & strFileName)

我尝试用Server.MapPath("../Templates/")替换Server.MapPath("/Templates/")但是这给了我IIS服务的根(C:\ InetPub \ wwwroot)而不是我的网站的根。如果我尝试Server.MapPath(strFileName)我会再次错误地找到该文件的路径,因为站点不在IIS根目录中,而是在驱动器上的其他位置。

任何想法如何解决?

1 个答案:

答案 0 :(得分:4)

问题是您没有在ASP应用程序配置中启用Enable parent paths

如果没有它,则不允许在ASP函数中使用..目录遍历。

Enable Parent Paths - IIS 6

有关详细信息,请参阅Enable Parent Paths Is Disabled by Default in IIS 6.0


  

旁注:

     

我倾向于简单地通过在IIS中将网站配置为单独的网站实例而不是使用%SystemDrive%\inetpub\wwwroot实例所在的Default Website来避免使用父路径。   这样做意味着像Server.MapPath("/")这样的代码有效,并指向您网站的根,而不是Default Web Site实例根。

相关问题