繁体   English   中英

如何将页面从asp.net发布到经典ASP

[英]How to post a page from asp.net to classic ASP

我想将一些表单变量发布到经典的ASP页面中。 我不想改变经典的ASP页面,因为需要完成大量的工作,以及消耗它们的页面数量。

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

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

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

我想将这些变量从ASP.NET提交到页面中,但登录控件嵌套在usercontrols和templates中,因此我无法将表单元素的名称设置为“username”和“UserPassword”。

有任何想法吗?

你无法真正“转发”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() ;
     }
}

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

没有 runat =“server”的情况下 ,在用户控件中使用简单的html作为用户名/密码文本框:

<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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM