A.ASP
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script>
function check()
{
document.form1.action="default2.aspx";
document.form1.submit();
}
</script>
</head>
<body>
<form id="form1" runat="server" method="post">
<div>
<input id="t1" type="text" /><input id="Button1" type="button" value="button" onclick="check();"/>
</div>
</form>
</body>
</html>
为什么我运行后会报
“/WebSite6”应用程序中的服务器错误。
--------------------------------------------------------------------------------验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script>
function check()
{
document.form1.action="default2.aspx";
document.form1.submit();
}
</script>
</head>
<body>
<form id="form1" runat="server" method="post">
<div>
<input id="t1" type="text" /><input id="Button1" type="button" value="button" onclick="check();"/>
</div>
</form>
</body>
</html>
为什么我运行后会报
“/WebSite6”应用程序中的服务器错误。
--------------------------------------------------------------------------------验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.HttpException: 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate。
{
document.form1.action="default2.aspx";
document.form1.submit();
}
这是啥?页面跳转?
a.aspx
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" method="post" action="default2.aspx">
<div>
<input id="t1" name="t1" type="text" />
<input id="Button1" type="submit" value="button"/>
</div>
</form>
</body>
</html>
default2.aspx.cs protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Request.Form["t1"]);
}
}
EnableViewStateMac ="false"
取消验证即可
可以在当前页面的<page ...>里加两个属性:
enableEventValidation="false" viewStateEncryptionMode ="Never"当然还可以在web.config里加入:
<pages enableEventValidation="false" viewStateEncryptionMode ="Never" />
我试过用URL带参数是可以的,但是这样参数在地址栏里出现不太好,所以想到用REQUET.FORM来接收,但是却不行.
如果你做,你是如何实现呢?
function check()
{
var value = document.getElementById("t1").value;
window.open("bb.aspx?t1=" + value);
} 在default2.aspx页面这样接收
if (Request.QueryString["t1"] != null)
{
Response.Write(Request.QueryString["t1"]);
}
按照你的意思,我写了两个页面, a.aspx用request.form方法传值到b.aspx, 实现了效果, 你试一下:说一下: 如果是用request.form取值, 表单中的runat="server"要去掉, 另外在HTML控件里不能只有ID, 而且还要加上name, 这样才可以取到值:a.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a.aspx.cs" Inherits="a" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" action="b.aspx" method="post">
<div>
请输入要验证的字符串:<input id="Text1" name="Text1" type="text" />
<input id="Submit1" type="submit" value="验 证" /></div>
</form>
</body>
</html>
a.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class a : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
}b.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="b.aspx.cs" Inherits="b" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class b : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("您要验证的字符串是:" + Request.Form["Text1"]);
}
}