FormsAuthentication与post与Request的问题,如果表单是get则ok,换成post则失败!
需求:WebForm1.aspx页面上的数据提交至WebForm2.aspx..现在中间加一道登录验证 Login.aspx
问题:
如果表单是get方式提交则ok,换成post则失败!why?部分代码:
=================================================================
WebForm1.aspx: <form id="Form1" method="post" action=WebForm2.aspx >
<FONT face="宋体"></FONT>
<input type=text id=xx name=xx />
<br>
<input type=submit value=submit />
<br>
</form>
=================================================================WebForm2.aspx.cs: private void Page_Load(object sender, System.EventArgs e)
{
// TextBox1显示WebForm1中提交过来的数据
this.TextBox1.Text = Request["xx"].ToString() ;
}
===============================================
Login.aspx.csif(this.TextBox1.Text == "a")
{
//Response.Write(FormsAuthentication.GetRedirectUrl("a", false));

if(true)
{
//测试过程中数据输入会进入此分支
FormsAuthentication.SetAuthCookie("a",false);
Response.Redirect(FormsAuthentication.GetRedirectUrl("a",false),false);

}
else
{
Response.Redirect("Default.aspx");
}
/**/}
else
{}

解决方案 »

  1.   

    第二问:
    在用get时,
    this.TextBox1.Text = Request["xx"].ToString() ;//这句可以取到数据
    this.TextBox1.Text = Request.Form["xx"].ToString() ;//这句取不到数据想问两者有何区别?
      

  2.   

    “/FormAuthenticationTest2”应用程序中的服务器错误。
    --------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
    搞了两个小时,还是报上面的错Server.Transfer(FormsAuthentication.GetRedirectUrl("a",false));也试了,照petshop上的例子一样的代码....
      

  3.   

    this.TextBox1.Text = Request.Form["xx"].ToString() ;
    只适合取post所提交的值。所以取不到。
      

  4.   

    post提交时,this.TextBox1.Text = Request["xx"].ToString() 也取不到...
      

  5.   

    google到两种方案:一种是session,不想用,麻烦
    二是否Server.Transfer...还要定义N多的属性,更麻烦,更不想用!post的数据在转发时到底能不能获得,救命啊,我快疯了!
      

  6.   

    get提交用Request.QueryString 取
    post提交用Request.Form取
    如可能既有get提交又post提交或不确定,可用Request取。(也可先判断提交方式)
    但是如有多个同名变量提交过来,取得的是一个集合,取值时要注意。