传统的ASP使用Server.Mappath()如预期在global.asa中不起作用 [英] Classic ASP Server.MapPath() doesn't work as expected in global.asa

查看:203
本文介绍了传统的ASP使用Server.Mappath()如预期在global.asa中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在经典的ASP,使用Server.Mappath()并不总是正确地在 Application_OnStart的事件中工作的的Global.asa 。我有一个ASP页的\\ testfolder \\ TEST.ASP虚拟根目录下,我在\\ XSL \\ transform.xslXSLT文件即可。我的虚拟根目录位于C:\\的Inetpub \\ wwwroot的\\ testapp \\

In Classic ASP, Server.MapPath() doesn't always work properly in the Application_OnStart event within global.asa. I have an ASP page at "\testfolder\test.asp" within a virtual root, I have an XSLT file at "\xsl\transform.xsl". My virtual root is located in "c:\inetpub\wwwroot\testapp\".

我使用的MapPath ASP页中获取完整路径XSLT文件。电话是:

I use MapPath within the ASP page to get the full path to the XSLT file. The call is:

sXslPath = Server.MapPath("xsl\transform.xsl")

有些时候,在MapPath回报C:\\的Inetpub \\ wwwroot的\\ testapp \\ XSL \\ transform.xsl如预期,其他时候,它错误地返回C:\\的Inetpub \\ wwwroot的\\ testapp \\ testfolder 的\\ XSL \\ transform.xsl。不正确的路径显然会导致严重的问题。

Some times MapPath returns "c:\inetpub\wwwroot\testapp\xsl\transform.xsl" as expected, other times it incorrectly returns "c:\inetpub\wwwroot\testapp\testfolder\xsl\transform.xsl". The incorrect path obviously causes serious problems.

推荐答案

我在这里回答我的问题:

发生此问题,因为在调用的时候 Application_OnStart的 的MapPath 包含不正确导致应用程序启动页面的上下文。如果当应用程序尚未开始运行的第一个ASP页面是不是在虚拟根的根和的MapPath 迷糊,并将该路径被称为ASP页面的路径返回

This problem occurs because when called in Application_OnStart, MapPath incorrectly includes the context of the page that caused the application to startup. If the first ASP page to be run when the application isn't yet started is not in the root of the virtual root then MapPath gets confused and adds the path to the called ASP page to the path it returns.

因此​​,举例来说,如果启动该应用程序是在页面的C:\\的Inetpub \\ wwwroot的\\ testapp \\ folder1中\\文件夹2 \\ TEST.ASP,然后在MapPath会错误地添加的\\文件夹1 \\文件夹2到路中间,并返回C:\\的Inetpub \\ wwwroot的\\ testapp \\ folder1中\\文件夹2 \\ XSL \\ transform.xsl

So for example if the page that started the app was in "c:\inetpub\wwwroot\testapp\folder1\folder2\test.asp" then MapPath would incorrectly add "\folder1\folder2" into the middle of the path and return "c:\inetpub\wwwroot\testapp\folder1\folder2\xsl\transform.xsl"

如果您的网站只有在根文件夹中有文件或不使用的MapPath 的Global.asa ,然后你就不会注意到这个小怪胎。我怀疑有很多经典的ASP网站在那里的那无法正常有时因为这个启动,但它们的主人只是做一个快速IISRESET,不知道什么很了问题。

If your website only has files in the root folder or doesn't use MapPath in global.asa then you will never notice this little oddity. I suspect there are lots of ASP Classic sites out there that fail to startup properly sometimes because of this, but their owners just do a quick iisreset, not knowing what quite went wrong.

这样做的结果是,你不能可靠地使用的MapPath 的Global.asa 如果你有一个网站,有ASP文件不仅仅是根文件夹其他任何地方

The result of this is that you can't reliably use MapPath in global.asa if you have a website that has ASP files anywhere other than just the root folder.

如果这是一个一次性的网站,那么最简单的解决方法就是硬code你使用任何路径的Global.asa

If it is a one-off website then the easiest solution is to just hard code any paths you use in global.asa.

如果你卖的产品基于ASP经典其他人则硬编码的路径是不是一种选择。您可能已移动的所有使用的的MapPath 出来的应用程序启动或编写的路径转换为您的ASP文件作为安装程序的一部分处理这一问题。

If you sell a product to other people based on ASP Classic then hard coding the paths is not an option. You either have to move all usage of MapPath out of the application startup or deal with the issue by writing paths into your ASP files as part of the installer.

这篇关于传统的ASP使用Server.Mappath()如预期在global.asa中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆