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

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 头痒头皮屑多掉头发怎么办 有头屑头痒掉头发怎么办 老是头痒掉头发怎么办 头屑头痒掉头发怎么办 头痒头屑多掉头发怎么办 洗头发时总是掉发怎么办 染头发染到脸上洗不掉怎么办 总爱掉头发怎么办20岁 头发开叉长的慢怎么办 洗头时掉很多头发怎么办 出门前头发很油怎么办 关于头发头顶头发少怎么办 每天掉100根头发怎么办 小孩嘴巴烂了该怎么办 小孩吃烧烤嘴巴肿好大该怎么办 脸特别瘦的人怎么办 怀孕宝宝太懒了怎么办 奶油胶手机壳脏了怎么办 为什么电脑桌面壁纸变成黑色怎么办 仓鼠妈妈老忘了宝宝怎么办 木工三排多轴钻床气缸坏了怎么办? 水溶笔洗不掉怎么办 针管笔没有墨了怎么办 二岁小儿不爱吃饭怎么办 狗狗一直挠痒痒怎么办 手被铅笔扎了怎么办 小孩智力轻度低下该怎么办 发侮辱人的信息怎么办 宋民国表情我能怎么办 苹果手机微信弄成听筒模式怎么办 我的小可爱丢了怎么办 法斗犬老是皮肤病看也看不好怎么办 项链水晶不亮了怎么办 美甲画画手抖怎么办 微信中的表情符号不全怎么办 球球大作战找不到团战服务器怎么办 小孩的腰有点弯怎么办 小朋友不听话被老师罚站怎么办 幼儿园小朋友被老师罚站怎么办 生完小孩弯腰驼背怎么办 小孩爱捡垃圾是怎么办