Tuesday, 11 June 2013

How to handle ViewState Exception

HttpApplication httpApp = this.Context.ApplicationInstance;
HttpException httpEx = httpApp.Server.GetLastError() as HttpException;
if (httpEx != null)
{
    if (
        httpEx.WebEventCode == System.Web.Management.WebEventCodes.AuditInvalidViewStateFailure
        ||
        httpEx.WebEventCode == System.Web.Management.WebEventCodes.InvalidViewState
        ||
        httpEx.WebEventCode == System.Web.Management.WebEventCodes.InvalidViewStateMac
        ||
        httpEx.WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorViewStateFailure
        )
    {
        HttpContext.Current.ClearError();
        Response.Write("Error: An invalid viewstate has been detected (WebEventCode: " + httpEx.WebEventCode.ToString() + ").");
    }
}

No comments:

Post a Comment

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...