Can I post values to classic ASP page when debugging?
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 tes开发者_Python百科ting. 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.
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
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" } );
});
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&anotherID=2
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
精彩评论