错误:此页面的状态信息无效,可能已损坏

时间:2011-07-05 04:40:45

标签: .net asp.net .net-4.0

我从dropdownlist回发时收到此异常。 注意:Dropdownlist与BigInt绑定为值类型,并在usercontrol中绑定。 当我在下拉列表中选择值时,我得到了这个例外:

The state information is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.

Source Error:

[No relevant source lines]


Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\074f73f4\bcce5747\App_Web_j32tj0nd.0.cs    Line: 0

Stack Trace:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9594283
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
   System.Convert.ToInt32(String value, IFormatProvider provider) +48
   System.Web.UI.Page.get_RequestViewStateString() +245

[ViewStateException: Invalid viewstate. 
    Client IP: ::1
    Port: 2479
    Referer: http://localhost:89//home.aspx?catid=8
    Path: /home.aspx
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110614 AskTbPTV2/3.12.2.16749 Firefox/3.6.18 GTB7.1
    ViewState: ]

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +198
   System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState) +14
   System.Web.UI.Page.get_RequestViewStateString() +567
   System.Web.UI.HiddenFieldPageStatePersister.Load() +241
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
   System.Web.UI.Page.LoadAllState() +43
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
   System.Web.UI.Page.ProcessRequest() +78
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.home_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\074f73f4\bcce5747\App_Web_j32tj0nd.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

我做了google并尝试了很多类似的事情: 在webconfig中:

<pages maxPageStateFieldLength="40" 

 ValidateRequest="false"

但没有解决方案。

专家请给我解决方案。从最近几个小时开始,我正面临这个问题,早些时候它工作正常。

编辑:注意:我现在已经测试过,发现UC在其他页面“TEST PAGE”上工作正常。我认为它必须与某些事情相冲突...请建议..

2 个答案:

答案 0 :(得分:2)

您的问题与页面/控件生命周期有关 - 当您修改控制树(或动态加载控件)时,在回发后。 ASP.NET期望存在相同的控制树,否则它无法正确加载视图状态并给出错误。

你的罪魁祸首是代码:

if (ShowTabbedFlash)
{
   UserControls.TabbedFlash tf = UserControls.TabbedFlash)Page.LoadControl("UserControls/TabbedFlash.ascx");
   Phtabbedflash.Controls.Add(tf);
}

通常,通过匹配控件ID来控制树匹配工作 - 通过不提供ID,ASP.NET将为控件生成ID - 如果在回发后更改这些,则ASP.NET运行时遇到特定id的错误控件类型同时恢复视图状态,从而恢复错误。为您的用户控件提供一些特定的ID,它应该可以工作(类似的逻辑将适用于页面上或用户控件内的任何此类动态加载的控件)。例如,

if (ShowTabbedFlash)
{
       UserControls.TabbedFlash tf = UserControls.TabbedFlash)Page.LoadControl("UserControls/TabbedFlash.ascx");
       tf.ID = "SomeUniqueID";
       Phtabbedflash.Controls.Add(tf);
}

答案 1 :(得分:0)

最后我解决了这个问题,但我仍然无法理解它的原因。

我解决了以下问题: 我的页面包含:

我的母版页包含一个属性:

 public bool ShowTabbedFlash
        {
            get { return showTabbedFlash; }
            set { showTabbedFlash = value; }
        }

protected void Page_Load(object sender, EventArgs e)
        {
            if (ShowTabbedFlash)
            {
                UserControls.TabbedFlash tf = (UserControls.TabbedFlash)Page.LoadControl("UserControls/TabbedFlash.ascx");
                Phtabbedflash.Controls.Add(tf);
            }
        }

在我的页面中:

<%@ MasterType VirtualPath="~/Main.Master" %>
Code i中的

是在母版页的属性中设置值:

private void ShowTabbedFlash()
        {
           Master.ShowTabbedFlash = true;
        }

现在我评论了改变母版页属性值的代码

// Master.ShowTabbedFlash = true;

它开始正常工作..

请高手提供一些知识,说明为什么会因为MasterPage的属性而发生这种情况?