I'd like to post some form variables into a classic ASP page. I don't want to have to alter the classic ASP pages, because of the amount of work that would need to be done, and the amount of pages that consume them.
The classic ASP page expects form variables Username and Userpassword to be submitted to them.
username = Request.Form("UserName")
userpassword = Request.Form("Userpassword")
It then performs various actions and sets up sessions, going into an ASP application.
I want to submit these variables into the page from ASP.NET, but the login control is nested inside usercontrols and templates, so I can't get the form element's names to be "username" and "UserPassword".
Any ideas?
Answers:
I'd like to post some form variables into a classic ASP page. I don't want to have to alter the classic ASP pages, because of the amount of work that would need to be done, and the amount of pages that consume them.
The classic ASP page expects form variables Username and Userpassword to be submitted to them.
username = Request.Form("UserName")
userpassword = Request.Form("Userpassword")
It then performs various actions and sets up sessions, going into an ASP application.
I want to submit these variables into the page from ASP.NET, but the login control is nested inside usercontrols and templates, so I can't get the form element's names to be "username" and "UserPassword".
Any ideas?
Answers:
You can't really "forward" a POST on, like you're wanting to do (in your OP). The client has to initiate the POST to your ASP page(s) (which the code in your second post is doing).
Here's the self-POSTing code from your own reply so you can mark an answer, like you suggested:
public class RemotePost{
private System.Collections.Specialized.NameValueCollection Inputs
= new System.Collections.Specialized.NameValueCollection() ;
public string Url = "" ;
public string Method = "post" ;
public string FormName = "form1" ;
public void Add( string name, string value ){
Inputs.Add(name, value ) ;
}
public void Post(){
System.Web.HttpContext.Current.Response.Clear() ;
System.Web.HttpContext.Current.Response.Write( "<html><head>" ) ;
System.Web.HttpContext.Current.Response.Write( string .Format( "</head><body onload=\"document.{0}.submit()\">" ,FormName)) ;
System.Web.HttpContext.Current.Response.Write( string .Format( "<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >" ,
FormName,Method,Url)) ;
for ( int i = 0 ; i< Inputs.Keys.Count ; i++){
System.Web.HttpContext.Current.Response.Write( string .Format( "<input name=\"{0}\" type=\"hidden\" value=\"{1}\">" ,Inputs.Keys[i],Inputs[Inputs.Keys[i]])) ;
}
System.Web.HttpContext.Current.Response.Write( "</form>" ) ;
System.Web.HttpContext.Current.Response.Write( "</body></html>" ) ;
System.Web.HttpContext.Current.Response.End() ;
}
}
Answers:
Don't use the asp.net login control (if you are).
Use simple html for the user name/password textboxes in your user control without runat="server":
<input type="text" name="UserName" />
<input type="password" name="Userpassword" />
<asp:Button ID="btnLogin" runat="server" PostBackUrl="Destination.asp" />
Set the PostBackUrl property on the button to you classic asp url and all should be fine.
Answers:
I found this on another site.
I will build up a small form with just the variables you want, and output it to the client and submit itself. It's pretty neat, but it comes with the problem of breaking the back button, and sending the password back to the client in a form unencrypted.
public class RemotePost{
private System.Collections.Specialized.NameValueCollection Inputs
= new System.Collections.Specialized.NameValueCollection() ;
public string Url = "" ;
public string Method = "post" ;
public string FormName = "form1" ;
public void Add( string name, string value ){
Inputs.Add(name, value ) ;
}
public void Post(){
System.Web.HttpContext.Current.Response.Clear() ;
System.Web.HttpContext.Current.Response.Write( "<html><head>" ) ;
System.Web.HttpContext.Current.Response.Write( string .Format( "</head><body onload=\"document.{0}.submit()\">" ,FormName)) ;
System.Web.HttpContext.Current.Response.Write( string .Format( "<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >" ,
FormName,Method,Url)) ;
for ( int i = 0 ; i< Inputs.Keys.Count ; i++){
System.Web.HttpContext.Current.Response.Write( string .Format( "<input name=\"{0}\" type=\"hidden\" value=\"{1}\">" ,Inputs.Keys[i],Inputs[Inputs.Keys[i]])) ;
}
System.Web.HttpContext.Current.Response.Write( "</form>" ) ;
System.Web.HttpContext.Current.Response.Write( "</body></html>" ) ;
System.Web.HttpContext.Current.Response.End() ;
}
}