已解决:IE 10 似乎在处理空字符方面存在问题。因为我们在服务器端生成大量代码,所以缓冲会导致列表项数据中出现 NULL 字符,这最终会破坏 ViewState(NULL 不是有效的 base64 字符)。我注意到了这一点,因为小型数据集没有发生损坏
我通过Response.Buffer = false
在生成列表项时进行设置解决了这个问题。我涉足的其他可能的解决方案:
-ListBox.DataSource = new DataView(dataTable)
对于ListBox.DataBind()
列表框数据。这导致了干净的数据,但在我的情况下需要更改存储过程
- 优雅地清除缓冲区,使 NULL 出现在<option>
元素之外
经过大量研究后,我仍然在我们的 Web 应用程序中遇到无效的视图状态错误。
总结一下:
- 我使用了我在网上找到的 ViewState 检查器,但它无法解析 ViewState,所以它没有帮助。第二对返回“不可读的数据”
- 仅在 IE 10 中一致。不显示在任何其他浏览器中
- 在文档模式 IE9 标准下工作正常(我们正在努力支持 IE10 标准)
- 页面上的两个主要字段(两个列表框)将无法使用
EnableViewState="False"
,因此有关此的解决方法不是所需的选项。 - 在检查了页面的源代码后,我
NUL
在 Base64 字符串中看到了一个字符。
我的猜测是 ViewState 在 NUL 字符处被截断,并且由于预期的 ViewState 与收到的不同而引发错误。但是,我坚持如何验证这一点,缩小导致数据损坏的原因,以及如何解决问题。
更新:我在数据集中发现了一个 NUL 字符,从 ViewState 中删除这个字符解决了这个问题……查看数据库,数据看起来完全没问题。想象一下这[NUL]
是一个合法的空字符
视图状态:
...pZmUFBTE[NUL]4NjoxZxAFD1RJQUEt...
列表框中的选项之一:
<option value="201:1" title="Pr[NUL]emier 20">Premier 20</option>
现在我想我需要追踪这种腐败发生在哪里?
代码
if (!IsPostBack)
{
System.Web.UI.WebControls.ListItem liListItem;
clsGLOBALGASubscription clsGAS = new clsGLOBALGASubscription(lngSubID);
DataTable dataTable = clsGAS.ListSelectedProducts(Session["GAID"].ToString().Trim());
if(dataTable == null)
{
lstbAvailable.Items.Add("There are no products available for your account. Please contact your administrator.");
btnAdd.Visible = false;
btnAddAll.Visible = false;
btnRemove.Visible = false;
btnRemoveAll.Visible = false;
}
else
{
if(Session["SelectedProducts"] != null && Session["SelectedProducts"].ToString().Trim().Length != 0)
{
foreach(DataRow dataRow in dataTable.Rows)
{
string strConcatIDs = dataRow["CompanyID"] + ":" + dataRow["SeriesID"];
liListItem = new ListItem(dataRow["Company"] + " - " + dataRow["Series"], strConcatIDs);
liListItem.Attributes.Add("title", String.Format("{0} - {1}", dataRow["Company"], dataRow["Series"]));
foreach(string subString in Session["SelectedProducts"].ToString().Split(delimiters))
{
if(subString == strConcatIDs)
if (xraeList)
{
foreach (string CarrierHealthItem in XraeCarrierList)
{
string[] CarrierInforArray = CarrierHealthItem.Split(':');
if (CarrierInforArray[0].ToString() == dataRow["CompanyID"].ToString())
{
foundXrae = true;
break;
}
}
if (foundXrae)
{
liListItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "Red");
liListItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold");
foundXrae = false;
}
}
lstbSelected.Items.Add(liListItem);
bSelectedAlready = true;
break;
}
}
if (bSelectedAlready == false)
{
if (xraeList)
{
foreach (string CarrierHealthItem in XraeCarrierList)
{
string[] CarrierInforArray = CarrierHealthItem.Split(':');
if (CarrierInforArray[0].ToString() == dataRow["CompanyID"].ToString())
{
foundXrae = true;
break;
}
}
if (foundXrae)
{
liListItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "Red");
liListItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold");
foundXrae = false;
}
}
lstbAvailable.Items.Add(liListItem);
}
else
{
bSelectedAlready = false;
}
}
}
else // ...no Selected Products, so just populate lstbAvailable
{
foreach(DataRow dataRow in dataTable.Rows)
{
liListItem = new System.Web.UI.WebControls.ListItem(dataRow["Company"] + " - " + dataRow["Series"], dataRow["CompanyID"] + ":" + dataRow["SeriesID"]);
liListItem.Attributes.Add("title", String.Format("{0} - {1}", dataRow["Company"], dataRow["Series"]));
if (xraeList)
{
foreach (string CarrierHealthItem in XraeCarrierList)
{
string[] CarrierInforArray = CarrierHealthItem.Split(':');
if (CarrierInforArray[0].ToString() == dataRow["CompanyID"].ToString())
{
foundXrae = true;
break;
}
}
if (foundXrae)
{
liListItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.Color, "Red");
liListItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold");
foundXrae = false;
}
}
lstbAvailable.Items.Add(liListItem);
}
}
}
}
}
错误:
The state information is invalid for this page and might be corrupted.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[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) +90
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +60
System.Web.UI.HiddenFieldPageStatePersister.Load() +173
[ViewStateException: Invalid viewstate.
Client IP: 10.128.3.10
Port: 44359
Referer: http://LTCarrierProduct.aspx?Title=Customize Carriers and Products&XraeValidation=Invalid
Path: /LTCarrierProduct.aspx
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
ViewState: /wEPDwUJNzE5MTU3Njg2D2QWBgIBDxYCHgRUZXh0BY4BPExJTksgaHJlZj0nU3R5bGVzL0xUU3R5bGVzLmNzcycgdHlwZT0ndGV4dC9jc3MnIHJlbD0nc3R5bGVzaGVldCcgLz48TElOSyBocmVmPSdTdHlsZXMvMDE1ODFfTFRTdHlsZXMuY3NzJyB0eXBlPSd0ZXh0L2NzcycgcmVsPSdzdHlsZXNoZWV0JyAvPmQCAw8WAh8AZWQCBQ9kFgQCAQ8QZA8WxgFmAgECAgIDAgQCBQIGAgcCCAIJAgoCCwIMAg0CDgIPAhACEQISAhMCFAIVAhYCFwIYAhkCGgIbAhwCHQIeAh8CIAIhAiICIwIkAiUCJgInAigCKQIqAisCLAItAi4CLwIwAjECMgIzAjQCNQI2AjcCOAI5AjoCOwI8Aj0CPgI/AkACQQJCAkMCRAJFAkYCRwJIAkkCSgJLAkwCTQJOAk8CUAJRAlICUwJUAlUCVgJXAlgCWQJaAlsCXAJdAl4CXwJgAmECYgJjAmQCZQJmAmcCaAJpAmoCawJsAm0CbgJvAnACcQJyAnMCdAJ1AnYCdwJ4AnkCegJ7AnwCfQJ+An8CgAECgQECggECgwEChAEChQEChgEChwECiAECiQECigECiwECjAECjQECjgECjwECkAECkQECkgECkwEClAEClQEClgEClwECmAECmQECmgECmwECnAECnQE...]
[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) +177
System.Web.UI.HiddenFieldPageStatePersister.Load() +11367569
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +11447671
System.Web.UI.Page.LoadAllState() +56
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11441698
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11441214
System.Web.UI.Page.ProcessRequest() +269
System.Web.UI.Page.ProcessRequest(HttpContext context) +167
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +625
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
来自服务器上的 ie.browsers:
<browser id="IE6to9" parentID="IE5to9">
<identification>
<capability name="majorversion" match="[6-9]" />
</identification>
<capture></capture>
<capabilities>
<capability name="jscriptversion" value="5.6" />
<capability name="ExchangeOmaSupported" value="true" />
</capabilities>
</browser>