ASP Classic: request function for url param not working? - asp.net

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

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 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

Failed to load viewstate error after moving website to a new server

I don't really know where to start with this one. I am getting:
`Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.`
after moving a website to a new server. The exact same code works on my other server. It happens when I submit one of my forms (but doesn't do it on all form submissions).
Any ideas what can cause this so I have somewhere to look?
Using: ASP.NET 2.
EDIT: I am adding some user controls to a placeholder dynamically at runtime but this same code is working ok on my other server. I have tried clearing the controls in the place holder before adding new ones (as I saw a post about that) but it hasn't helped.
EDIT2: It seems that the postback is just failing. It isn't going into the onClick code of the button either so something is deffintiely screwy .. If I try / catch the exception it seems that all the controls are still added successfully ... Setting my Dynamic UC's to EnableViewState = false resolves this particular error.
EDIT3: Ok, I think I may have a handle on what is happening. For some reason on the old server the form action is default.aspx?action=amend but the new server is showing amend.html?action=amend so I think the re-write module is messing up in IIS. This would explain the control adding issue as well because the action is happening 2 times (I think). I will look into the Rewrite module and see if anything is wrong then post back.
Please, have a look at these articles:
http://blog.typps.com/2008/01/failed-to-load-viewstate-typical.html
http://weblogs.asp.net/guys/archive/2004/12/05/275321.aspx
Or try a simple temporary solution - disable viewstate for this placeholder. Either way, I'm puzzled why it actually works on your first server. I'd be glad if someone else will be able to clarify this subject more.
It turns out that the post back Url for the form is wrong on this server (unsure why at the moment, I will update when I know). This is causing the dynamic controls to be added in an unexpected way and causing the error. I noticed this when I managed to post my form and the content didn't update. I manually adjusted the action url using firebug and all is well.
Worth looking at walther's answer regarding dynamic controls and the viewstate though.
Not sure what caused it but I am manually setting the form action in the page load now and it seems to have solved the issue.

Use asp include to include asp.net page

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

ASP.NET cookies for ASP page

I have a wierd situation where I have an ASP.NET page that sends the user to the ASP page, and data is passed from one to the other via query string.
I've been assigned the task of changing this so that cookies are used instead of query strings.
I'm a little clueless here. Is this possible? How do I get started? Do I need to worry about anything special because one page is ASP.NET and the other ASP ? I also cannot be totally reliant on Javascript because of those once-in-a-while user visitors who have Javascript turned off.
This is pretty simple.
As long as you are not setting a 'Session Cookie', the cookie is set on the browser.
I'm doing it here...when the user logs in and wants me to remember his username:
Set the cookie in ASP.NET:
Response.Cookies.Add(new HttpCookie("RememberMeUserName", owner.Username));
View the value in ASP:
Response.Write(Request.Cookies("RememberMeUserName"))
Both the ASP.NET & ASP pages must be on the same domain name.
Ed B seems to have it - further reading available here:
http://ryangaraygay.com/blog/post/Updating-ASP-cookie-from-ASPNET-vice-versa.aspx
I also found this : http://www.eggheadcafe.com/tutorials/aspnet/198ce250-59da-4388-89e5-fce33d725aa7/aspnet-cookies-faq.aspx
With gotcha's concerning IE 6 and fixes! Also has information on how to store multiple values in them.

Resources