หน้า 1 จากทั้งหมด 1

Validation of viewstate MAC failed.

โพสต์แล้ว: 22/02/2011 4:01 pm
โดย jataz2
ถ้าใช้ .net 2.0 เเล้วเจอ error ดังนี้ 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

มีวิธีเเก้คือ เพิ่ม "PostBackUrl = #"
ดังตัวอย่างนี้ครับ <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Search" PostBackUrl="#" />

Root Cause

This exception appears because Controls using DataKeyNames require Viewstate to be encrypted. When Viewstate is encrypted (Default mode, Auto, is to encrypt if controls require that, otherwise not), Page adds <input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" /> field just before closing of the <form> tag. But this hidden field might not have been rendered to the browser with long-running pages, and if you make a postback before it does, the browser initiates postback without this field (in form post collection). End result is that if this field is omitted on postback, the page doesn't know that Viewstate is encrypted and causes the aforementioned Exception. I.E. page expects to be fully-loaded before you make a postback.