Search code examples
asp-classicmismatch

Classic ASP - Strange Type Mismatch error


Here is a sample code to simulate the problem:

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

As you can see, functs.asp is included inside buy.asp file. This way it works without problems (errors) when open http://localhost/main.asp?d=buy. But now I am trying to include functs.asp inside main.asp, like this:

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

Well, when included functs.asp inside main.asp, I got an error message:

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

Please, can someone help me? I really do not know what is going on...

Thanks!


Solution

  • It's not strange but an expected behaviour of Server.Execute in fact.

    From Remarks section:

    If a file is included in the calling page by using #include, the executed .asp will not use it. For example, you may have a subroutine in a file that is included in your calling page, but the executed .asp will not recognize the subroutine name. You must include the file in each executed .asp that requires the subroutine.