Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Error:The state information is invalid for this page and might be corrupted

I have no JQuery or other javascript changing values or html-structure. And I have no controls that is added dynamically.

Still I get the error: The state information is invalid for this page and might be corrupted

The error occurs somewhat random. Here is how I can replicate the issue, aspx-file:

<%@ Page ViewStateEncryptionMode ="Never" MaxPageStateFieldLength="40" ValidateRequest="false" Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="tbTest.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>tbTest </title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Button id="Submit1" type="submit"  
        runat="server" onClick="btnclick_Click" Text="Submit" /><br />
    <asp:TextBox ID="tbStatus" enableViewState="true" runat="server" TextMode="MultiLine" 
        Width="617px" Height="67px" ReadOnly="True" Font-Size="Smaller"></asp:TextBox>
    <br />
   </form>
</body>
</html>

.cs-file:

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Init(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DateTime timestamp = DateTime.Now;
            try
            {
                tbStatus.Text = timestamp.ToString() + ". Page Loaded. ";
            }catch (Exception ex) {
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                Response.Cache.SetNoStore();
            } catch (Exception ex){
            } 
        }    
    }

    protected void btnclick_Click(object sender, EventArgs e)
    {
        DateTime timestamp = DateTime.Now;
        try
        {
            tbStatus.Text += Environment.NewLine + timestamp.ToString() + ". TextBox updated. ";

        } catch (Exception ex) {
            tbStatus.Text += Environment.NewLine + timestamp.ToString() + ". Error. " + ex.Message.ToString();
        }
    }
}

This really gives me head-ache. After 3-4 submits the error is there. I have tested changing values for ViewStateEncryptionMode, MaxPageStateFieldLength, ValidateRequest, AutoEventWireup and EnableEventValidation without success.

What can be wrong?

like image 606
Peter Wirdemo Avatar asked Jan 17 '14 12:01

Peter Wirdemo


People also ask

How do you fix the state information is invalid for this page and might be corrupted?

Just set the enableEventValidation attribute in the web. config file for the asp.net application to false. IIS compression enabled on IIS6 can also cause this. Verify this is turned off.

What causes invalid viewstate errors?

The error message is caused by some exception being thrown when the view state is being processed. The problem is that the exception is being consumed, and its details are lost in the error message. By using a debugger, you can determine the original exception.

What does invalid viewstate mean?

Invalid viewstate can happen for a variety of reasons. Viewstate is too big and has not finished rendering before a user causes a postback on the page.

Which view causes the problem of slow loading the page due to its large viewstate?

ASP.NET is a fantastic web application development platform but using it can mean performance problems caused by viewstate.


2 Answers

I had searched many pages and finally this is working for me

protected override object LoadPageStateFromPersistenceMedium() 
{ 
return Session["_ViewState"]; 
}
protected override void SavePageStateToPersistenceMedium(object viewState) 
{ 
Session["_ViewState"] = viewState; 
}
like image 171
Bhaumik Brahmbhatt Avatar answered Oct 26 '22 13:10

Bhaumik Brahmbhatt


I had the same issue without errors in the code. What helped me out was to restart the asp.net session state service:

enter image description here

like image 45
Stefan Michev Avatar answered Oct 26 '22 13:10

Stefan Michev