【问题标题】:The state information is invalid for this page and might be corrupted. (Only in IE)此页面的状态信息无效,可能已损坏。 (仅在 IE 中)
【发布时间】:2012-01-20 18:49:39
【问题描述】:

谁能帮我解决这个例外。我已经尝试了几个修复,但没有任何效果。我只在 IE(7、8 和 9)中得到这个异常。

当我第一次加载页面时,它会弹出一个下拉菜单。我选择一个特定的供应商,它会发回一个页面并返回所需的信息。如果我更改供应商,它仍然会加载信息。当我使用 $.ajax 请求动态地将控件加载到页面上而不是返回并更改下拉选择(选择不同的供应商)时,它会出错并给我以下异常。同样,它只发生在 IE 中。

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:\Users\tmalik\AppData\Local\Temp\Temporary ASP.NET Files\root\6691c708\751e6443\App_Web_a3kdfsht.2.cs    Line: 0 

Stack Trace: 


[FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. ]
   System.Convert.FromBase64String(String s) +0
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +77
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
   System.Web.UI.HiddenFieldPageStatePersister.Load() +147

[ViewStateException: Invalid viewstate. 
    Client IP: 127.0.0.1
    Port: 
    Referer: http://localhost:57289/vendor.aspx
    Path: /vendor.aspx
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MDDR)
    ViewState: 2D1IMRanPXfVARbRp1ooiwD71WHybNzxSNLbbA0G3MxKeo7m52dHWLBPGdnMH5JthTnPVt7UES/PVx39dfZYHbr0/DL7J58mvA2I4wRUSdDShVxvZqC7ZPZWcatowpZ7VYaD9PFKW7OkgppCwmePFuYnpU8kWDT5TvSLqN50Flrqpv0zCM9YoCKemfesa68rqBkkSTijcxnxdDCgvzSl72giI4ZhwK92wD22Ma6scW4PFjRZeTsKoowJq+JqJGuBMEepwKguFUy4dX86UIULnJ7NQsgZW1aQvpZdnfSRCSYrWhFWPhKTPsS622eaQYShsxddPs/mfEB26f54WS+iBYuk3mWm8jr6sWvsOIRtwH8b3E/5UujbgAxTNVg8BhzpSFvmE4KwGKo0tKuuqOFtP0pjpaAI7fV3EQ1M7BVQSAVrtBevRFJ0PlCPrU2aQms2LVeE5POqTJGtY+74xWkdCtLzT04Ug4R+SMBRElQBqX/5A54OHj2ghYjJ/3tgg4ToGUX2xrQ/c70lrphP+kabGVM2Op4DFjZAaOZj/CDVUurH2BYXKuJdUvzbf2zHngoOnqZGqrw3n6V6HGcnHNKxfuGQ20MPdxJYCbYHGiRqixzV1NxJoHFHbYCVx3IlrqF0W44AFKm2gzzk3V8zu9lUjyFNvUNBMjNaZeekLtcWpszhKrm8WhVnWQAk1CXxKJqyK0RC3...]

[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) +235
   System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState) +14
   System.Web.UI.HiddenFieldPageStatePersister.Load() +251
   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.vendor_aspx.ProcessRequest(HttpContext context) in c:\Users\tmalik\AppData\Local\Temp\Temporary ASP.NET Files\root\6691c708\751e6443\App_Web_a3kdfsht.2.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

【问题讨论】:

  • 我会追查这个:“输入不是有效的 Base-64 字符串,因为它包含非 base 64 字符、两个以上的填充字符或非空白字符填充字符。”
  • 我想我知道我的问题。在页面上添加动态控件(ajaxly)会改变视图状态,当我们回发页面时,它会抛出异常,因为视图状态已经改变。我已经使用 hack 在 pagepost 上使用 jquery 删除所有占位符(即 Div)。这意味着删除所有添加的视图状态。这是我的解决方案 $("#VendorListDropDownSearchable").change( function () { $("#UserControl1DIV").remove(); $("#UserControl2DIV").remove(); });
  • 太棒了!如果您确认这可以解决您的问题,请返回此处并创建一个答案。这将真正帮助其他肯定会在这里找到路的人。我自己也有同样的错误信息,只是不记得了。回答您自己的问题是完全可以的(常见问题解答中是这样说的)。

标签: jquery asp.net internet-explorer viewstate


【解决方案1】:

好的,这就是我想出的解决方案/hack。我的问题是在页面上动态添加用户控件(通过 ajax 请求)正在更改页面的视图状态并引发异常。经过研究,我发现 viewstate 存储页面的状态(属性和设置)。一旦您从 Web 服务返回控件 html,就会有某种视图状态存储到页面上。并且当您回发到服务器时,它会在解密视图以重建页面时抛出异常。我只是使用 jquery 删除了页面回发上的那些控件(动态添加的),问题就解决了。

//In my case "VendorListDropDownSearchable", causes the page post back.
    $("#VendorListDropDownSearchable").change( function () {
        $("#UserControl1DIV").remove(); //removing the place holder holding control1
        $("#UserControl2DIV").remove(); //same as above
    });

【讨论】:

  • Tauseef @Tauseef 嗨有同样的问题。仅在 ie 中。
  • 完全有同样的问题。感谢您发布答案!
  • 我在 IE9 中遇到了同样的问题(尽管该页面在 IE10 中运行良好)。在尝试运行一些 C# 代码之前,我必须在我的 ASP.Net 按钮中添加一个 OnClientClick 来调用像你这样的 Javascript 函数,以重定向到不同的 ASP.Net 页面。
【解决方案2】:

我知道这个问题已经得到解答,但这里有几个其他选项:

1)。如果您通过 jquery .load() 进行 Web 服务调用,则可以在返回时使用加载回调参数删除视图状态

$('#myDiv').load('/MyPage.aspx', null, function(){ 
     $('.aspNetHidden', this).remove(); // removes viewstate from returned aspx html
});

2)。使用 Html Agility Pack 在呈现返回的控件之前,您可以在 Web 服务中执行相同的操作。假设您正在调用一个 Web 服务,该服务在服务中加载 UserControl.ascx,然后在返回之前将其呈现为 html。

[WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod]
public string GetControlHtml()
{

// do stuff to get the control you want

....

Page page = new Page();
HtmlForm form = new HtmlForm();
var ctl = (MyControlsNameSpace.Controls.MyControl)page.LoadControl("Controls\\MyControl.ascx");

page.Controls.Add(form);
form.Controls.Add(ctl);
StringWriter result = new StringWriter();
HttpContext.Current.Server.Execute(page, result, false);

// Extension Method RemoveViewStateFromControl
var MyControlsHTML = result.RemoveViewStateFromControl();
return MyControlsHTML;

}

.....

// In an extensions class....
public static string RemoveViewStateFromExecuteControl(this StringWriter writer)
    {
        HtmlAgilityPack.HtmlDocument Doc = new HtmlDocument();
        Doc.LoadHtml(writer.ToString());
        var Divs = Doc.DocumentNode.SelectNodes("//div");
        if (Divs != null)
        {
            foreach (var Tag in Divs)
            {
                if (Tag.Attributes["class"] != null)
                {
                    if (string.Compare(Tag.Attributes["class"].Value, "aspNetHidden", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        Tag.Remove();
                    }
                }
            }
        }

        return Doc.DocumentNode.OuterHtml;
    }

【讨论】:

  • +1 为您的#1 答案:$('.aspNetHidden', this).remove();我在我的内部(加载了 jquery 的)页面上尝试了 EnableViewState="false", EnableViewStateMac="false", ViewStateMode="Disabled",这些都没有阻止 aspNetHidden div 的出现,这弄乱了父页面的视图状态。 (对我来说,错误适用于所有浏览器。)
  • 这是实际问题。谢谢!
【解决方案3】:

就我而言,问题在于有两个<form></form> 标签。

我的主页中有一个文本框。如果用户在此 TextBox 中输入一个值,则脚本会转到另一个页面并在用户继续编写该值时搜索该值。通常我通过单击WebsiteAdd New Item 创建了这个“另一个”页面。所以 Visual Studio 为我创建了一个新页面。像往常一样,这个新页面中也有<form></form> 标签。于是我删除了这个标签,问题就解决了。

以下是我的代码:

(PS:我用的是MasterPage。但下面的代码只需要在我的主页中使用)

    Dim scriptText As String
    scriptText = ""
    scriptText += "function serinogoster(str) {" + Chr(10)
    scriptText += "var xhttp;" + Chr(10)
    scriptText += "if (str == '') {" + Chr(10)
    scriptText += "document.getElementById('ctl00_ContentPlaceHolder1_Label19').innerHTML = '';" + Chr(10)
    scriptText += "return;" + Chr(10)
    scriptText += "}" + Chr(10)
    scriptText += "xhttp = new XMLHttpRequest();" + Chr(10)
    scriptText += "xhttp.onreadystatechange = function() {" + Chr(10)
    scriptText += "if (this.readyState == 4 && this.status == 200) {" + Chr(10)
    scriptText += "document.getElementById('ctl00_ContentPlaceHolder1_Label19').innerHTML = this.responseText;" + Chr(10)
    scriptText += "}" + Chr(10)
    scriptText += "};" + Chr(10)
    scriptText += "xhttp.open('GET', 'serinover.aspx?serino='+str, true);" + Chr(10)
    scriptText += "xhttp.send();" + Chr(10)
    scriptText += "}" + Chr(10)
    Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), "OnKeyUpScript", scriptText, True)
    TextBox6.Attributes.Add("onkeyup", "serinogoster(this.value);")

在上面的代码中serinover.aspx是第二个页面,不应该有<form></form>标签。

【讨论】:

    【解决方案4】:

    清空您“隐藏”加载的 div。我发现清空 div 或将其设置回原始文本(我的是加载消息)都有效。

    <a class="popmodal" href="YOUR HREF HERE">View History</a>
    
    
        $('.popmodal').on('click', function (e) {
                    e.preventDefault();
                    $('#modalViewBenefitsHistory').modal('show').find('.modal-content').load($(this).attr('href'));
                });
    
    
        $('#modalViewBenefitsHistory').on('hidden.bs.modal', function (e) {
                    $('.modal-content').empty();
                })
    
    --OR
    
    $('#modalViewBenefitsHistory').on('hidden.bs.modal', function (e) {
                $('.modal-content').text("&nbsp;Loading your benefits history...please wait a moment.");
            })
    
    
    
    <div id="modalViewBenefitsHistory" aria-hidden="true" class="modal fade">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                &nbsp;Loading your benefits history...please wait a moment.
            </div>
        </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多