使用asp include包含asp.net页面

时间:2010-12-20 17:31:17

标签: asp.net asp-classic

我有一个asp页面,它使用includes来包含某些页面,具体取决于查询字符串。 我在asp.net中为这个页面添加了一个新功能,并希望在asp页面中包含我的新页面,但是我收到了这个错误。

  Active Server Pages error 'ASP 0140'

    Page Command Out Of Order

    /d//Default.aspx, line 1

    The @ command must be the first command within the Active Server Page. 

4 个答案:

答案 0 :(得分:2)

您不能在ASP页面中包含ASP.NET页面。但是,你有两个选择。

最简单的方法是将ASP.NET页面作为IFrame包含在ASP页面上。您可以使用ASP在服务器端动态设置IFrame的URL。

另一种选择是编写一个包装器.NET DLL,它将通过一种方法呈现您的页面。然后,您可以在COM +中注册该DLL,以便可以在ASP页面中通过VBScript调用它。显然这更复杂。

如果第一个选项有效,那就去吧。否则你可能需要弄清楚如何实现第二个。

答案 1 :(得分:1)

我很确定ASP中的include功能是严格包含其他ASP文件,其中包含要由ASP引擎解析的代码。它不知道如何处理ASP .NET代码。

答案 2 :(得分:1)

您不能在ASP页面中包含ASP.NET页面。你不能在同一个回复中混合它们。

使用Response.Redirect改为重定向到ASP.NET页面。

请注意,您实际上选择要在ASP页面中包含的页面,您始终包含所有页面,因为包含在任何ASP之前完成代码启动,然后条件语句只决定运行哪个页面。

答案 3 :(得分:0)

我同意Justin Niessner的选择,但还有另一种简单的方法可以将ASP.net页面的内容包含在您的Classic ASP页面中,这可能符合您的需求。

如果要包含ASP.net页面的结果Html,可以采用以下方法:

Dim Url
Url = "http://pathtoyourasp.net/script/somescript.aspx?param=value"    

' Create XML object, make server side request 
Dim objXML: set objXML = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXML.Open "GET", Url, True
objXML.Send

' Retry a few times just in case: it's classic ASP.
Dim try_times: try_times = 0
While objXML.ReadyState <> 4 and try_times < 5
    objXML.waitForResponse 2
    try_times = try_times + 1
Wend
If objXML.ReadyState = 4 then
    ' Success, write the response
    Response.Write objXML.ResponseText
Else
    ' Failed, show error
    Response.Write "The page failed to load."
End If
Set objXML = Nothing