Use asp include to include asp.net page - asp.net

I have an asp page that uses includes to include certain pages 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

Related

ASP Server.Execute - Executed Page is not accessing variables from the former/first page

I already know that Server.Execute(..) does not accept query strings. The MSDN website says that all variables from the former website are avaible to the executed page. However it does not work for me at all. Any idea why?
Simple example that should work but it does not:
<%
Dim strVar
strVar = "This Text"
Server.Execute("page2.asp")
%>
Page2.asp
<%
Response.Write( strVar )
%>
any idea why this does not work?
ps. I´m not using "< !--include .. -->" because I have conditional outputs.
When using Server.Execute, variables from page 1 are not available on page 2, so by design your example should not work.
Here's a snippet from the MSDN page for Server.Execute that explains what is available from page 1 on page 2.
The following collections and properties are available to the executed
ASP page:
Application variables, even if they are set in the calling page.
Session properties, even if they are set in the calling page.
Server variables and properties, even if they are set in the calling page.
Request collections and properties, even if they are set in the calling page. This includes Form and QueryString data passed to the calling page.
Response collections and properties. The executed .asp file may modify HTTP headers. However, as with any .asp file, if the executed .asp file attempts to modify HTTP headers after it sends a response to the client, it generates an error.

ASP Classic: request function for url param not working?

I usually don't deal with the old ASP pages of our websites. I have not changed any code in these pages. But all of the sudden, all the pages with a request("param") fail to load correctly.
This is basically how it is structured. All my pages have a few other .asp files included. On each of them I wrote something like response.write("test") at the end to make sure that the execution of the page was going through and it did. Then on my page I try to access, I tried at the very first line after all inclusions response.write("test") and this display the test message. Nevertheless, if I add just before that the statement request("param") BIM! no test message displayed.
I have no idea what it could be and even how I could debug it. Would you have any suggestions?
Again, I did not change any ASP code and it was working fine. The only thing I can think of is I added a new website on the server and I created a binding to that new website. But I did not add any binding to the previous website where ASP pages are. I don't know if it is related. This is also happening only on our test server. The production website is working fine.
EDIT: I noticed a server error saying The Template Persistent Cache initialization failed for Application Pool 'local.website1.com' because of the following error: Could not create a Disk Cache Sub-directory for the Application Pool. The data may have additional error codes. Could that be related?
EDIT: I just tried to change request("param") by Request.QueryString("param") and this worked but I don't want to edit every single page where I have request. How is this happening...
EDIT: another thing I tried. I emptied my page which now only has
<%
request("param")
response.write("test")
%>
I access to that page from a link on a previous page. Going on my page with the link, I won't have the test message displayed. But if I go back in the url in the browser and hit enter (accessing the page directly, not like a link) it will display "test". Should I investigate the previous page instead? Is it something general linked to the parameter passing?
EDIT: one more thing done.
On my page A pagea.aspx where I have my link to myasppage.asp?param=value, I created two links. One is a asp:linkbutton where I set postBackUrl = myasppage.asp?param=value; in the back. The other link is asp:hyperlink where I set navigateUrl = myasppage.asp?param=value;. The link from the hyperlink control works. The link from the linkButton does not work.
The app pool for Classic ASP needs to run in Classic, rather than Integrated mode. Create a new app pool for the new web site if it is currently using the same app pool as the website1 site.
I jogged my memory by searching for "Request Form in Classic ASP stops working" or something similar.
I apologize for not thinking of this earlier. At least my previous answer was a good lesson in debugging. I hope you won't need to much Rograine to grow back the hair loss.
If the case is that you want to use the shorthand request("param") versus the long form request.querystring("param") or request.form("param") then you need to keep in mind that this shorthand method is not only sloppy in terms of coding but can also cause problems like you are having.
I am not sure in exactly what order things go in. But I think that request("param") will retrieve querystring params first, then forms, then cookies. (I may be wrong about that order). Where this because bad in terms of programming say you are using request("fname") instead of request.form("fname") to get data from a submitted form. But the url is form.asp?timestamp=234234. ASP is going to go after the querystring paramters and "fname" is going to be empty because it doesnt exist in the querystring. ASP is not smart enough to hunt for the parameter in all three (forms,querystring,cookies) objects.
Either clean up your code to request.form / request.querystring. Or investigate further to make sure the urls which are not working for you dont have hidden querystrings in them. A querystring might even show up if you have an IIS rewrite rule enabled which gives you pretty URLs.
Try this code to investigate what variables are working:
<%
Response.Write ("<b>All form Variables</b><br>")
For Each Item In Request.Form
xName = Item
xValue = Request.Form(Item)
Response.Write("Name: " & xName & " | Value: " & xValue & "<BR>" )
Next
Response.Write ("<BR><b>All QuersyString Vars</b><br>")
For Each Item In Request.Querystring
xName = Item
xValue = Request.Querystring(Item)
Response.Write("Name: " & xName & " | Value: " & xValue & "<BR>" )
Next
%>
If the above code ends up giving you both Form and Querystring variables (on the page in question) then you know you have an issue with ASP not knowing what object you are using.
This is too much text for a comment, so I'll post it as a answer. I hope you don't mind doing one more test. Frank suggested enabling detailed errors (enable detailed errors in IIS). Please do this if you haven't already done so. Early in your question you stated the following code failed.
<%
request("param")
response.write("test")
%>
Please add the folloiwng debugging lines to the test
<%
on error resume next
request("param")
response.write "<br />Error number " & Err.number
response.write "<br />Error description" & Err.Description
%>
Hopefully, this will give us some more detail about what the issue is. I suspect you're right about investigating the error you found. I found some posts about that issue which you may want to check out.
ASP Security error in IIS7
Could not create a Disk Cache Sub-directory for the Application Pool
(IIS7)
These two sites reference this site: Template Persistent Cache initialization failed for Application Pool" on IIS 7 using Classic ASP

ASP classic code keeps reloading

I have an ASP.NET website that includes few aspx pages that run the classic ASP code. The below query is written in classic asp code and it is using the App_Code file (dbConn) to run the query.
<%
SQL1 = "INSERT INTO table (field1, field2, field3) VALUES ('" & value1 & "', '" & value2 & "', '" & value3 & "')"
dbConn.ExecuteCommand(SQL1)
%>
The problem that I am facing is that the file having the query, suppose it as "query.aspx", keeps recalling the query and filling the database with same entries infinite times even though the page "query.aspx" is called only once in the other file as
<!-- #include file="inc/query.aspx" -->
My question is, why does the page keeps executing the query over and over again even though it has been included only once in the entire project? Is the page "query.aspx" called more than once even if it is not included more than once?
The first thing to understand here is that *.aspx pages are ASP.Net, not classic ASP.
With that information in hand, we also need to understand some things about how ASP.Net handles pages. If you are using web forms, ASP.Net does a lot of work to hide the HTTP Request/Repsonse model from you. Instead, you are presented with a model that tries to make a web page seem like a Windows Form: you get a form instance from which you can add and remove controls.
Except that's not quite right. You don't really get a form instance. You only get a Form type. ASP.Net does not completely hide the request/response model. Each request to your page works with a different instance of your form than the last request, even within the same user and session. Each control event that you handle results in a new request, and every time this happens, the ASP.Net runtime has to rebuild your entire page instance from scratch.
What this means is that one user viewing one ASP.Net page will cause the code for that page to run several times as they interact with the page. If you have an <!-- #include directive on that page, the directive will be re-executed for every control event.
To fix this, first replace the Query.aspx file with a database class that supports sending query parameter data separately from the sql command string. Then put code like this inside your *.aspx pages to use that new class:
Sub Page_Load
If Not IsPostBack
' Call the database code from here
End If
End Sub

ASP script code inside ASP.NET page?

how to use ASP code inside ASP.NET ?
is it possible to run ASP script code inside ASP.NET page ?
If so, please give an example.
thanks
--
ASP code might look like this. So how do we such such script inside ASP.NET ?
Function changeColor(value, random)
Dim colorArray
colorArray = Split(value, ",")
divBlockColor = colorArray(random Mod (UBound(colorArray) + 1))
End Function
I'm affraid it isn't possible, as ASP Code runs in a different application environment as asp.Net. That's also why for example session("xyz") is not shared between Classic ASP and ASP.Net web pages in the same website.
What you could do is leave the asp code in a .asp page, and use forms with POST to go back and forth to the asp code. This way you will not have to rewrite the entire .asp environment, and you can migrate to .Net one bit at a time.
This way you can leave all your existing code, and use simple javascript to automatically submit the forms, posting the values back to .Net

Embedding ASPX in ASP page

I have an ASPX based component which I'd need to inlude into a plain ASP based
script. Scenario is, that I'm working within an LMS system (Angel to be exact)
and I wan't to create a new nugget within that framework. An Angel nugget is
pretty much what a portlet is in the Java world.
Now, the nugget spec. states that my starting point has to be a file called
default.asp. What I'd like to do is:
read relevant data from ASP session
pass data to ASPX component
have ASPX do it's job and display the results
My problem is that I fail to run / display my ASPX component without
using an iframe, which I want to avoid since that crushes the layout /
design of my nugget.
Is there a way to get this done properly or do I have to rewrite my
component in ASP to get this going?
Note: the component performs
web service queries and such and I'd like to avoid rewriting that.
Why don't you grab the .aspx content from the .asp page using the MSXML object?
url = "http://www.yoururl.com/YourPage.aspx?relevantData=YourRelevantData"
Set xml = Server.CreateObject("Msxml2.SERVERXMLHTTP")
xml.Open "GET",url,False
xml.send
html = xml.ResponseText
Set xml = Nothing
Response.Write(html)

Resources