ASP Server.MapPath() doesn’t work as expected in global.asa
来源:互联网 发布:abode软件 编辑:程序博客网 时间:2024/05/18 18:43
问题描述:
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/".
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")
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.
问题解决:
This problem occurs because when called in Application_OnStart, MapPathincorrectly includes the context of the page that caused theapplication to startup. If the first ASP page to be run when theapplication isn't yet started is not in the root of the virtual rootthen MapPath gets confused and adds the path to the called ASP page to the path it returns.
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"
If your website only has files in the root folder or doesn't use MapPath in global.asathen you will never notice this little oddity. I suspect there are lotsof ASP Classic sites out there that fail to startup properly sometimesbecause of this, but their owners just do a quick iisreset, not knowingwhat quite went wrong.
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.
If it is a one-off website then the easiest solution is to just hard code any paths you use in global.asa.
If you sell a product to other people based on ASP Classic then hardcoding the paths is not an option. You either have to move all usage ofMapPath 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的使用:
http://www.jb51.net/article/5897.htm
本文参考 :http://stackoverflow.com/questions/496524/classic-asp-server-mappath-doesnt-work-as-expected-in-global-asa
- ASP Server.MapPath() doesn’t work as expected in global.asa
- ViewPager.setOffscreenPageLimit(0) doesn't work as expected
- Ant task doesn't work in Eclipse
- background-size doesn't work in IE8
- ASP Global.asa 文件
- ASP Global.asa 文件
- MSTest doesn’t work
- set_terminate doesn't work
- vi doesn't work
- TLS doesn't work on PPPoE in Chelan: MTU issue
- topmargin=\"0\" doesn\'t work in Firefox?
- GroupName of radiobutton doesn't work in gridview
- Dib to Bitmap doesn't work in WPF
- Problem: Jasper Server Excel Export Configuration Doesn't Work
- ASP Global.asa 参考(1)
- ASP Global.asa 参考(2)
- ASP Global.asa 参考(3)
- Why dynamic_cast doesn't work ?
- 相对论通俗演义(1-10) 第五章
- 相对论通俗演义(1-10) 第六章
- 《代码大全》第二版 读后感
- excel2003函数应用完全手册
- 数组和List之间相互转换的方法
- ASP Server.MapPath() doesn’t work as expected in global.asa
- 受挫了
- 相对论通俗演义(1-10) 第七章
- 【转】模糊排序问题(Fuzzy sort)
- 相对论通俗演义(1-10) 第八章
- C与C++关于不完整类型的说明
- 相对论通俗演义(1-10) 第九章
- pku 2184 Cow Exhibition(经典DP)
- 相对论通俗演义(1-10) 第十章