Validation of viewstate MAC failed while submit a form on page load
I have a sample page called Redirect.aspx with following content;
<body onload="document.forms.container.submit()">
<form id="container" runat="server" method="post" name="container">
<input type="hidden" value="<%=Request["APP_ID"]%>" name="APP_ID" />
</form>
</body>
the Page_Load
method is following:
protected void Page_Load(object sender, EventArgs e)
{
container.Action = Configuration.Instance.PageToRedirect;
}
To this Redirect.aspx page, I'm directed from some external page. In the request context, I have APP_ID key, which is passed from this external page. Next, I want to pass this APP_ID value 开发者_C百科using POST to some other page, which is defined in the configuration. Unfortunately, I'm getting such error while redirecting:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I don't want to disable view state validation (<pages enableViewStateMac="false">
) because this is not the "solution" I want to apply.
Besides I don't understand why I'm getting such an error. Can someone get me through this ? Is there any other way to automatically submit a form on Page_Load
event ?
Regards
2 ideas:
Check if the value of <%=Request["APP_ID"]%> gets actually calculated and you are not posting that as a string. You can't post any html tag characters like "<" or ">". If the value doesn't get calculated it means you are not databinding the page. A quick solution would be putting this.DataBind() in your code behind file.
Generate a MachineKey manually in your web.config (you can use an online tool to do that: http://aspnetresources.com/tools/machineKey). In one of my application it solved my problems even if I'm not in a web farm (now I don't remember the details of the problem though).
Also please clarify this: "Next, I want to pass this APP_ID value using POST to some other page, which is defined in the configuration" are you sure the error happens when you do the redirect as you state, or is it in this post? Are you trying to cross post a value to another application in a different domain? That is not possible normally.
i think, you can edit your pages tag in web.config with:
<pages maxPageStateFieldLength="512">
maybe, it can fix your problem...
精彩评论