2008-10-31 56 views
5

我想发布一些表单变量到一个经典的ASP页面。我不想改变传统的ASP页面,因为需要完成的工作量以及使用它们的页面数量。如何发布一个页面从asp.net到传统的ASP

传统的ASP页面需要将表单变量Username和Userpassword提交给它们。

username = Request.Form("UserName") 
userpassword = Request.Form("Userpassword") 

然后它执行各种操作并建立会话,进入ASP应用程序。

我想将这些变量提交到ASP.NET的页面中,但登录控件嵌套在usercontrols和模板中,所以我无法获得表单元素的名称为“用户名”和“用户密码”。

任何想法?

+0

你有没有得到这个工作,张贴到一个传统的ASP页面?我已经得到了一切,以便将密钥注册到RemotePost对象,但之后无法在经典的ASP页面上检索它们。 – 2015-03-04 20:06:59

回答

4

你不能真正“转发”POST,就像你想做的一样(在你的OP中)。客户端必须启动POST到您的ASP页面(第二篇文章中的代码正在执行)。


这里的自邮政代码从自己的回复,所以你可以标记一个答案,像你这样的建议:

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() ; 
    } 
} 
0

我在another site找到了。

我将建立一个只包含所需变量的小表单,并将其输出到客户端并提交。它非常整洁,但它带有打破后退按钮的问题,并以未加密的形式将密码发送回客户端。

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() ; 
    } 
} 
+0

不要担心未加密地发回密码 - 毕竟,这就是它的方式。另外,你应该在那里放置一个提交按钮和一条消息,让非JS用户点击。 – 2008-11-02 00:14:11

+0

谢谢马克。如果有人在整体上发布答案,我会接受答案。 – digiguru 2008-11-03 09:27:01

1

不要使用asp.net登录控件(如果你是)。

使用简单的HTML在你的用户控件的用户名/密码文本框没有 RUNAT =“服务器”:

<input type="text" name="UserName" /> 

<input type="password" name="Userpassword" /> 

<asp:Button ID="btnLogin" runat="server" PostBackUrl="Destination.asp" /> 

按钮PostBackUrl属性设置为您传统的ASP网址和所有应该没事。

+0

好的 - 但我猜这意味着我不能在提交它们之前用用户名和用户密码的值进行任何服务器端的操作? – digiguru 2008-10-31 15:14:57

相关问题