Wednesday, November 10, 2010

Validation of viewstate MAC failed

Error message:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey & validation algorithm. AutoGenerate cannot be used in a cluster.

Solution:
Disable viewstate change by adding this to the affected aspx page.
EnableViewState="false" EnableEventValidation="false" enableViewStateMac=false

For example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="myLogin" EnableViewState="false" EnableEventValidation="false" enableViewStateMac=false %>

Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Today I encountered this weird error after I published my ASP.NET to the server.
Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Solution:
1. In login.aspx.cs
Change public partial class Login : System.Web.UI.Page to public partial class myLogin : System.Web.UI.Page

2. In login.aspx
Change <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
to <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="myLogin" %>