我正在运行一些带有各种 GridView 的 c# .net 页面。如果我将其中任何一个单独留在网络浏览器中较长时间(通常是过夜),当我单击页面上的任何元素时,我会收到以下错误。
我不太确定从哪里开始处理这个问题。如果页面的 View 状态已过期,我不介意重置页面,但抛出错误是 Not Acceptable !
Error: The state information is invalid for this page and might be corrupted.
Target: Void ThrowError(System.Exception, System.String, System.String, Boolean)
Data: System.Collections.ListDictionaryInternal
Inner: System.Web.UI.ViewStateException: Invalid viewstate. Client IP: 66.35.180.246 Port: 1799 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0 ViewState: (**Very long Gibberish Omitted!**)
Offending URL: (**Omitted**)
Source: System.Web
Message: The state information is invalid for this page and might be corrupted.
Stack trace: at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded() at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) at System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) at System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
最佳答案
这很奇怪,因为 ViewState 作为字符串存储在网页本身中。所以我不明白长时间会如何导致该错误。也许页面上的一个或多个对象已被垃圾收集或应用程序重置,因此 View 状态引用旧控件,而不是应用程序重新启动时创建的控件。
无论如何,我感受到你的痛苦,这些错误调试起来从来都不是一件愉快的事,除了研究how ViewState works之外,我没有关于如何找到问题的简单答案。
关于c# - 如何优雅地处理ViewState错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73380/