【发布时间】:2013-07-23 16:40:37
【问题描述】:
已解决: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"一起使用,因此不适合使用解决方法。 - 检查页面源后,我在 Base64 字符串中看到了一个
NUL字符。
我的猜测是 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>
【问题讨论】:
-
您是否尝试将更新的浏览器定义文件放入 App_Browsers 文件夹?
-
从我的 ie.browser 文件中添加了相关行,如果相关请告诉我
-
我想是这样,但那里可能还有其他条目 - 你能附上整个
ie.browserfile 吗? -
添加了另一个更新。我已经在导致错误的数据中找到了一个 NUL 字符。我仍然不确定这些数据是如何被破坏的
-
所以 [NUL] 不是来自数据库?它如何/何时出现在表单上?
标签: c# .net viewstate internet-explorer-10