Validation of viewstate MAC failed.

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderators: mindphp, ผู้ดูแลกระดาน

User avatar
PHP Super Member
PHP Super Member
Posts: 254
Joined: 22/02/2011 11:48 am

Validation of viewstate MAC failed.

Post by 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.
  • Similar Topics
    Last post

Return to “Programming - C/C++ & java & Python”

Who is online

Users browsing this forum: No registered users and 7 guests