开发者

ASP.net post with runat=server error:Validation of viewstate MAC failed

Hi i have the following code:

<!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>
  <title></title></head><body><form method="POST" action="search.aspx" runat="server">     Name <input type="text" name="Name"/>Age <input type="text" name="Age"/><input type="submit" /></form></body></html>

It's simple asp.net form with two fields name and age and a submit button. but When i click the submit button, i recieve the following error:

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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: 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.

This error disappears if i remove runat=server from the form. Unfortunately i have a dropdown list which to populated from db with runat=server in the form tag. Any idea why i can't post using runat=server? the code that i will be using for drop down list is as follows:

<label>Location</label> <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:web3ConnectionString1 %>" 
    SelectCommand="SELECT DISTINCT location FROM properties"></asp:SqlDataSource>


            <asp:DropDownList id="location" runat="server" DataSourceID="SqlDataSource2" DataTextField="location" DataValueField="location" >开发者_Go百科


            </asp:DropDownList>

but before that the simple form needs to start posting values.

Regards, Sohail.


Your form tag is malformed. It should look more like:

<form id="MyForm" runat="server">

It shouldn't specify method or action. These specifications may be ruining your viewstate or changing the MAC in some way.


If this application isn't running on a web farm, try setting the enableViewStateMac key to false in the web.config:

<pages enableViewStateMac="false">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜