2008-10-31 61 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

相關問題