控制面板 - 帮助中心 - 付款方式 - 常用文档 - 软件下载 -   
服务中心
当前位置:首页 - 服务中心 - 网络学院

ASP动态包含解决办法

  因为asp的include是先于asp代码优先执行,所以无论用if else等等均不能分条件包含asp文件。可以用下面的函数代替

Function include(filename)
 Dim re,content,fso,f,aspStart,aspEnd
 
 set fso=CreateObject("Scripting.FileSystemObject")
 set f=fso.OpenTextFile(server.mappath(filename))
 content=f.ReadAll
 f.close
 set f=nothing
 set fso=nothing
 
 set re=new RegExp
 re.pattern="^\s*="
 aspEnd=1
 aspStart=inStr(aspEnd,content,"<%")+2
 do while aspStart>aspEnd+1
  Response.write Mid(content,aspEnd,aspStart-aspEnd-2)
  aspEnd=inStr(aspStart,content,"%\>")+2
  Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write "))
  aspStart=inStr(aspEnd,content,"<%")+2
 loop
 Response.write Mid(content,aspEnd)
 set re=nothing
End Function

被包含的文件中不要再包含其它文件。

更新时间:2010-10-12

7*24小时咨询热线:400-628-6536 0371-86013552 19937165195
传真:0371-86013552-6612 服务邮箱:web@3a88.com 代理邮箱:agent@3a88.com 备案邮箱:beian@3a88.com
运营商:郑州金飞科技有限公司 工商营业执照号:9141010567945717XL
公司地址:郑州高新技术产业开发区木兰里9号1号楼1单元14层310号 邮政编码:450000 豫ICP备12025635号-1 豫公网安备 41010502003077号