質問

いくつかのフォーム変数を従来のASPページに投稿したいと思います。必要な作業量とそれらを消費するページの量のため、従来のASPページを変更する必要はありません。

従来のASPページでは、フォーム変数UsernameとUserpasswordが送信されます。

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

その後、さまざまなアクションを実行してセッションを設定し、ASPアプリケーションに入ります。

これらの変数をASP.NETからページに送信したいのですが、ログインコントロールがユーザーコントロールとテンプレート内にネストされているため、フォーム要素の名前を" username"にできません。および" UserPassword"。

アイデアはありますか

役に立ちましたか?

解決

本当に「転送」することはできませんあなたがやりたいように(あなたのOPで)POST。クライアントは、ASPページへのPOSTを開始する必要があります(2番目の投稿のコードが実行しています)。


提案されたように、回答にマークを付けることができるように、ここにあなた自身の返信からの自己投稿コードがあります:

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

他のヒント

asp.netログインコントロールを使用しないでください(使用している場合)。

ユーザーコントロールのユーザー名/パスワードテキストボックスに単純なhtmlを使用 なし runat =&quot; server&quot;:

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

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

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

ボタンのPostBackUrlプロパティを従来のasp urlに設定すると、すべて問題ありません。

別のサイトでこれを見つけました。

必要な変数だけで小さなフォームを作成し、それをクライアントに出力して自分自身を送信します。それはかなりきれいですが、戻るボタンを壊し、暗号化されていない形式でクライアントにパスワードを送り返すという問題があります。

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() ;
     }
} 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top