ViewState仅在IE 10中无效

本文关键字:无效 IE 仅在 ViewState | 更新日期: 2023-09-27 18:24:23

已解决:IE 10似乎在处理null字符方面存在问题。由于我们在服务器端生成了大量代码,缓冲导致列表项数据中出现NULL字符,最终损坏了ViewState(NULL不是有效的base64字符)。我注意到这一点是因为损坏并没有发生在小型数据集

我已通过在生成列表项时设置Response.Buffer = false解决了此问题。我尝试过的其他可能的解决方案:

-列表框数据的ListBox.DataSource = new DataView(dataTable)ListBox.DataBind()。这导致了干净的数据,但在我的情况下需要更改存储过程

-优雅地清除缓冲区,使NULL出现在<option>元素之外

经过大量研究,我仍然在我们的web应用程序中遇到一个无效的视图状态错误。

总结:

  • 我使用了我在网上找到的ViewState检查器,但它无法解析ViewState,所以没有帮助。第二对返回"Unreadable data"
  • 仅在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

来自服务器上的浏览器:

<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>

ViewState仅在IE 10中无效

不确定这是否有帮助,但这是我们ie.browser:中的附加部分

 <browser id="IE5to9" parentID="IE">
    <identification>
        <capability name="majorversion" match="^[5-9]|[1-9]'d+" />
    </identification>
    <capture>
    </capture>
    <capabilities>
        <capability name="activexcontrols"     value="true" />
        <capability name="backgroundsounds"    value="true" />
        <capability name="cookies"             value="true" />
        <capability name="css1"                value="true" />
        <capability name="css2"                value="true" />
        <capability name="ecmascriptversion"   value="1.2" />
        <capability name="frames"              value="true" />
        <capability name="javaapplets"         value="true" />
        <capability name="javascript"          value="true" />
        <capability name="jscriptversion"      value="5.0" />
        <capability name="msdomversion"        value="${majorversion}${minorversion}" />
        <capability name="supportsCallback"    value="true" />
        <capability name="supportsFileUpload"  value="true" />
        <capability name="supportsMultilineTextBoxDisplay" value="true" />
        <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
        <capability name="supportsVCard"       value="true" />
        <capability name="supportsXmlHttp"     value="true" />
        <capability name="tables"              value="true" />
        <capability name="tagwriter"           value="System.Web.UI.HtmlTextWriter" />
        <capability name="vbscript"            value="true" />
        <capability name="w3cdomversion"       value="1.0" />
        <capability name="xml"                 value="true" />
    </capabilities>
</browser>

为我们解决了很多问题。试试看。