开发者

Use asp include to include asp.net page

I have an asp page that uses includes to include certain pages 开发者_StackOverflow中文版depending on the query string. I have built an addition to this page in asp.net and want to include my new page in the asp page, but i get this error.

  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. 


You can't include ASP.NET pages inside of an ASP page. You do, however, have a couple of options.

The easiest would be to include the ASP.NET page as an IFrame on your ASP page. You can use ASP to dynamically set the URL of the IFrame on the server side.

The other option would be to write a wrapper .NET DLL that would render your page via a method. You could then register that DLL in COM+ so that it could be called by VBScript in your ASP pages. Obviously this is more complicated.

If the first option works, go for it. Otherwise you might have to figure out how to implement the second.


I'm pretty sure the include functionality in ASP is strictly for including other ASP files which contain code to be parsed by the ASP engine. It wouldn't know what to do with ASP .NET code.


You can't include an ASP.NET page in an ASP page. You can't mix them in the same response.

Use Response.Redirect to make a redirect to the ASP.NET page instead.

Note that you are actually not selecting what page to include in your ASP page, you are always including all of the pages, as the include is done before any ASP code starts, and then the conditional statements only decide which of the pages to run.


I agree with Justin Niessner's options, but there is also another easy way to include the contents of the ASP.net page into your Classic ASP page, which might suit your needs.

If you want to include the resulting Html of the ASP.net page, you can take the following approach:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜