2012-01-20 45 views
7

任何人都可以幫助我解決這個例外。我嘗試了幾個修復程序,但沒有任何工作。我只在IE中獲得這個例外(7,8和9)。該頁面的狀態信息無效,可能已損壞。 (只在IE中)

當我第一次加載頁面時,它會彈出下拉菜單。在那裏我選擇一個特定的供應商,它使頁面回發並返回所需的信息。如果我更改供應商,它仍然會加載信息。當我使用$ .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 
+1

我會追查下列內容:「輸入不是有效的Base-64字符串,因爲它包含非基本64字符,多於兩個填充字符或填充字符中的非空白字符。」 – DOK

+1

我想我知道我的問題。在頁面上添加動態控件(ajaxly)會改變視圖狀態,當我們回傳頁面時,它會拋出一個異常,因爲viewstate已經改變了。我使用了黑客手段來刪除所有佔位符(即div),使用jquery在pagepost上返回。這意味着刪除所有添加的視圖狀態。 這裏是我的解決方案 $( 「#VendorListDropDownSearchable」)變化(函數(){ $( 「#UserControl1DIV」)刪除(); $( 「#UserControl2DIV」)刪除(); }。 ); – Tauseef

+1

太棒了!如果您確認這解決了您的問題,請回到此處並創建答案。這真的會幫助其他人肯定會在這裏找到他們的方式。我自己也有這個完全相同的錯誤信息,只是不記得了。回答你自己的問題是完全沒問題的(在常見問題解答中這樣說)。 – DOK

回答

11

好吧,這裏是解決方案/黑客我想出了。我的問題是動態地(通過ajax請求)添加一個用戶控件到頁面上正在改變頁面的視圖狀態,並拋出一個異常。經過研究,我發現viewstate存儲頁面的狀態(屬性和設置)。一旦你從一個web服務返回控件的html,就會有一些存儲在頁面上的viewstate。並且,當您回發到服務器時,它會在解密視圖重建頁面時引發異常。我只是簡單地刪除了這些控件(它是動態添加的),在頁面上使用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 
    }); 
+0

Tauseef @Tauseef你好有同樣的問題。只在ie。 – Mohammadreza

+0

完全有相同的問題。感謝您發佈答案! –

+0

我在IE9中遇到了同樣的問題(IE10雖然可以正常工作)。我必須在我的ASP.Net按鈕上添加一個OnClientClick,以在嘗試運行一些C#代碼之前調用與您的Javascript函數類似的Javascript函數,以重定向到不同的ASP.Net頁面。 –

4

我知道這已經回答了,但這裏有幾個其他選項:

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你的#1答案:$('。aspNetHidden',this).remove();我在內部(jquery加載)頁面上嘗試了EnableViewState =「false」,EnableViewStateMac =「false」,ViewStateMode =「Disabled」,但沒有一個阻止aspnetHidden div顯示哪一個弄亂了父頁面的視圖狀態。 (錯誤適用於所有瀏覽器。) –

+0

這是實際問題。謝謝! – CodeIt

1

在我的情況下,問題是有兩個<form></form>標籤。

我在我的主頁中有一個TextBox。如果用戶在此TextBox中輸入值,則腳本會轉到另一個頁面並在用戶繼續寫入時搜索該值。通常我通過點擊WebsiteAdd New Item創建了這個「另一個」頁面。所以Visual Studio爲我創建了一個新頁面。像往常一樣,在這個新頁面中也有<form></form>標籤。所以我刪除了這個標籤,問題就解決了。

下面是我的代碼:

(PS:我用的母版,但只在我的主網頁需要下面的代碼)

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>標籤。

相關問題