现在的位置: 首页 > 综合 > 正文

asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!)

2013年05月08日 ⁄ 综合 ⁄ 共 794字 ⁄ 字号 评论关闭

我想用post的方式把一个页面表单的值,传到另一个页面。当我点击Default.aspx的Send提交按钮时,这个时候会action到Default2.aspx页面,在这个时候就报错了,报的错误是:Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey>configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster(不理解为什么是这样!)

解决办法:在要接受的页面Default2.aspx加上<%@ Page Language="C#"  enableViewStateMac="false" %> 这个,就可以了!

Default.aspx页面的代码:

    <form id="form1" method="post" action="Default2.aspx" runat="server">
    <div>
        你的名字<asp:TextBox ID="name" runat="server"></asp:TextBox>
        <br />
        <br />
        <input type="submit" value="Send" />
        <br />
        <br />
        学习request 和 response的用法<br />
        <br />
        <br />
    </div>
    </form>

Default2.aspx页面代码:

string name = Request["name"];
Response.Write(name
+ "<br>");
Response.Write(
"你使用的是" + Request.RequestType + "方式传送数据");

只是在page_load里面加了接受form表单值的代码!

抱歉!评论已关闭.