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

我的梦境 提交于 2020-01-02 04:59:05

问题


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?


回答1:


Just set the enableEventValidation attribute in the web.config file for the asp.net application to false.

might also need to check http://blog.syedgakbar.com/2007/11/one-possible-reason-for-the-state-information-is-invalid-for-this-page-exception/

And

http://support.microsoft.com/default.aspx?scid=kb;EN-US;829743

IIS compression enabled on IIS6 can also cause this. Verify this is turned off.




回答2:


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; 
}



回答3:


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




回答4:


Adding this in webconfig in system.web tag solved my problem.

<pages controlRenderingCompatibilityVersion="4.0" maintainScrollPositionOnPostBack="true" validateRequest="false" />



回答5:


remove if you have <div><input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="#" /></div> in masterpage



来源:https://stackoverflow.com/questions/21185954/asp-net-errorthe-state-information-is-invalid-for-this-page-and-might-be-corrup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!