views:

44

answers:

4

Hello..

I have a classic ASP page that requires two values from a form. These values are posted to the ASP page from another pages form. I would like to pass these values to the ASP page without the need for a form for testing. Is this possible?

This is what the asp page looks like:

<%@LANGUAGE="JavaScript"%>
<%
var someID = new String( Request.Form("someID") );
var anotherID = new String( Request.Form("anotherID") );
%>

Ideally I would like to have VS pass values to 'someID' and 'anotherID' when debugging is started.

A: 

You could probably do a static HTML page that references jQuery and the following script that will execute a post on page load

$(document).ready(function(){
    $.post("[url to your page goes here]", { someID: "someValue", anotherID: "someValue2" } );
});
R0MANARMY
+2  A: 

There are plenty of command-line tools that can execute a POST request without building a form; the simplest one is probably cURL.

curl -d someID=someValue&anotherID=someOtherValue http://localhost/myASPPage.asp
JacobM
The only (possibly) difficult part of this approach is, if he's using the web server built into visual studio, making sure this command runs after the the server spins up and debugger is attached.
R0MANARMY
A: 

Or, you could set your variables to use Request.QueryString() during testing and then reference your ASP page with variables via a URL

<%@LANGUAGE="JavaScript"%>
<%
var someID = new String( Request.QueryString("someID") );
var anotherID = new String( Request.QueryString("anotherID") );
%>

URL

http://myhost.com/myASPPage.asp?someID=1&amp;anotherID=2
Tommy
A: 

You could probably do this from your C# code using the WebClient.UploadValues method:

http://msdn.microsoft.com/en-us/library/9w7b4fz7.aspx

If you need to actually redirect the user to your classic ASP page with the values posted, you might have more difficulty (all of the standard methods of redirecting via ASP.NET only do GET requests, but my understanding is that you will need a POST request for the values to go into the Request.Form collection on the classic ASP page). A Server.Transfer call might be able to do what you want, and I also found some code here that claims to be able to do that:

http://www.codeproject.com/KB/aspnet/ASP_NETRedirectAndPost.aspx

Rudism