经典ASP - 奇怪的类型不匹配错误

时间:2016-05-23 17:58:10

标签: asp-classic mismatch

以下是模拟问题的示例代码:

functs.asp

<%
Function SecureStr(Str)
  Dim Res
  Res = Trim(Str)
  If (Res <> "") Then
    Res = Replace(Res, "'", "")
    Res = Replace(Res, ";", "")
    Res = Replace(Res, "=", "")
  End If
  SecureStr = Res
End Function
%>

main.asp

<%
Option Explicit
Dim Dept
Dept = Request.QueryString("d")
%>
<html>
<body>
<%=Server.Execute(Dept & ".asp")%>
</body>
</html>

buy.asp

<!--#include file="functs.asp"-->
<%
Dim Name
Name = SecureStr(Request.Form("name"))
%>
BUY CONTENT

如您所见,functs.asp包含在buy.asp文件中。这种方式在打开http://localhost/main.asp?d=buy时没有问题(错误)。但现在我想在main.asp中包含functs.asp,如下所示:

main.asp

<%
Option Explicit
Dim Dept
Dept = Request.QueryString("d")
%>
<!--#include file="functs.asp"-->
<html>
<body>
<%=Server.Execute(Dept & ".asp")%>
</body>
</html>

buy.asp

<%
Dim Name
Name = SecureStr(Request.Form("name"))
%>
BUY CONTENT

好吧,当在main.asp中包含functs.asp时,我收到一条错误消息:

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'SecureStr'
/buy.asp, line 3

拜托,有人可以帮帮我吗?我真的不知道发生了什么......

谢谢!

1 个答案:

答案 0 :(得分:1)

这并不奇怪,但实际上是Server.Execute的预期行为。

来自Remarks部分:

  

如果使用#include将文件包含在调用页面中,则   执行.asp不会使用它。例如,您可能有一个子程序   在您的调用页面中包含的文件中,但执行的.asp   将无法识别子程序名称。您必须包含该文件   每个执行.asp都需要子程序。

相关问题