Sunday, April 26, 2015


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.


Hầu hết các website bằng asp.net thường mắc lỗi. 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.
Khi ta chạy website viết bằng ASP.NET trên web-hosting mà có nhiều website cùng chạy, mỗi khi ta cập nhật thư viện, assembly, mã nguồn mới (các file cs), khi đó nếu người dùng submit lên từ một trang được sinh ra từ code cũ có thể sẽ gặp phải lỗi “Validation of viewstate MAC failed”. Trong bài viết này tôi sẽ hướng dẫn cách khắc phục triệt để lỗi trên.

Cách giải quyết thứ nhất:
Thêm đoạn cấu hình sau vào trong thẻ trong file web.config

Xem thêm cách thông tin machineKey tại MSDN: machineKey Element
Để sinh machineKey bạn có thể sử dụng Tool sinh machineKey online

Paste the machine key in your applications web.config file under