HttpException (0x80004005):会话数据太长

本文关键字:数据 会话 0x80004005 HttpException | 更新日期: 2023-09-27 18:02:00

我的Web应用程序使用MVC 3,我得到这个错误:

会话数据太长

描述:在执行过程中发生未处理的异常当前的web请求。请查看堆栈跟踪了解更多信息有关错误及其在代码中的起源的信息。

异常详细信息:System.Web.HttpException: Session data is too long.

源错误:

的过程中产生了一个未处理的异常当前的web请求。关于来源和地点的信息可以使用下面的异常堆栈跟踪来识别异常。

堆栈跟踪:


[HttpException (0x80004005): Session data is too long.]System.Web.Providers.DefaultSessionStateProvider.SaveItemToSession(会话session, SessionStateStoreData项,布尔压缩,Int32最大长度)+ 205
System.Web.Providers.DefaultSessionStateProvider.SetAndReleaseItemExclusive (HttpContext上下文,字符串id, SessionStateStoreData项,对象lockId,布尔值newItem) + 534
System.Web.SessionState.SessionStateModule.OnReleaseState(对象来源EventArgs EventArgs) +1021
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute ()+ 80 System.Web.HttpApplication。ExecuteStep(IExecutionStep step, Boolean&completedSynchronously) + 165

版本信息:Microsoft .NET Framework Version:4.0.30319;ASP。净版:4.0.30319.18447

我试着用谷歌搜索,但是以前没有人知道。

下面是我的网页。配置文件,可能从这里的问题:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>
    <section name="RetryPolicyConfiguration" type="Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.RetryPolicyConfigurationSettings, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling, Version=5.1.1209.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="typeRegistrationProvidersConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.TypeRegistrationProvidersConfigurationSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <sectionGroup name="telerik">
      <section name="webAssets" type="Telerik.Web.Mvc.Configuration.WebAssetConfigurationSection, Telerik.Web.Mvc" requirePermission="false" />
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
    ...
  </configSections>
  <RetryPolicyConfiguration defaultRetryStrategy="Fixed Interval Retry Strategy">
    <incremental name="Incremental Retry Strategy" />
    <fixedInterval name="Fixed Interval Retry Strategy" />
    <exponentialBackoff name="Exponential Backoff Retry Strategy" />
  </RetryPolicyConfiguration>
  <typeRegistrationProvidersConfiguration>
    <clear />
    <add name="Caching" sectionName="cachingConfiguration" />
    <add name="Cryptography" sectionName="securityCryptographyConfiguration" />
    <add name="Exception Handling" sectionName="exceptionHandling" />
    <add name="Instrumentation" sectionName="instrumentationConfiguration" />
    <add name="Logging" sectionName="loggingConfiguration" />
    <add name="Policy Injection" sectionName="policyInjection" />
    <add name="Security" sectionName="securityConfiguration" />
    <add name="Data Access" providerType="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
    <add name="Validation" providerType="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationTypeRegistrationProvider, Microsoft.Practices.EnterpriseLibrary.Validation" />
    <add sectionName="RetryPolicyConfiguration" name="RetryPolicyConfiguration" />
  </typeRegistrationProvidersConfiguration>
  <connectionStrings>
    ...
  </connectionStrings>
  <appSettings>
    <add key="RunScheduler" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="aspnet:MaxHttpCollectionKeys" value="100000" />
  </appSettings>
  <system.web>
    <customErrors mode="Off" />
    <httpHandlers>
      <add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add verb="GET,HEAD" path="asset.axd" validate="false" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
      <add type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=8.0.14.225, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" path="Telerik.ReportViewer.axd" verb="*" />
    </httpHandlers>
    <compilation targetFramework="4.5.1" debug="true">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Telerik.ReportViewer.WebForms, Version=8.0.14.225, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" />
        <add assembly="Telerik.Reporting, Version=8.0.14.225, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" />
      </assemblies>
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </buildProviders>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="/Login.aspx" timeout="15" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="VPAdmin.Common" />
        <add namespace="VPAdmin.Models" />
        <add namespace="VPAdmin.ViewModels" />
        <add namespace="Telerik.Web.Mvc.UI" />
      </namespaces>
    </pages>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
    <sessionState mode="Custom" customProvider="DefaultSessionProvider" timeout="15">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers" connectionStringName="VisionPOS_masterConnectionString" />
      </providers>
    </sessionState>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="Elfo.Infrastructure.Service.WCF.WcfRequestProcessor" behaviorConfiguration="RequestProcessorBehavior">
        <endpoint address="" contract="Elfo.Infrastructure.Service.WCF.IWcfRequestProcessor" binding="basicHttpBinding" bindingConfiguration="RequestProcessorBinding" />
        <endpoint address="json" contract="Elfo.Infrastructure.Service.WCF.IWcfRestJsonRequestProcessor" binding="webHttpBinding" behaviorConfiguration="restBehavior" />
        <endpoint address="jsonp" contract="Elfo.Infrastructure.Service.WCF.IWcfRestJsonRequestProcessor" bindingConfiguration="webBindingWithJsonP" binding="webHttpBinding" behaviorConfiguration="restBehavior" />
      </service>
    </services>
    <client>
      ...
    </client>
    <bindings>
      <webHttpBinding>
        <binding name="webBindingWithJsonP" />
      </webHttpBinding>
      <basicHttpBinding>
        <binding name="RequestProcessorBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="RequestProcessorBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="1000000" maxConcurrentInstances="1000000" maxConcurrentSessions="1000000" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp defaultOutgoingResponseFormat="Json" />
        </behavior>
        <behavior name="RequestProcessorBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.net>
    <mailSettings>
      ...
    </mailSettings>
  </system.net>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="asset" />
      <add name="asset" preCondition="integratedMode" verb="GET,HEAD" path="asset.axd" type="Telerik.Web.Mvc.WebAssetHttpHandler, Telerik.Web.Mvc" />
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add name="Telerik.ReportViewer.axd_*" type="Telerik.ReportViewer.WebForms.HttpHandler, Telerik.ReportViewer.WebForms, Version=8.0.14.225, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" path="Telerik.ReportViewer.axd" verb="*" preCondition="integratedMode" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Drawing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Core" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Configuration" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Services" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Xml.Linq" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <telerik>
    <webAssets useTelerikContentDeliveryNetwork="false" />
  </telerik>
  <!-- logging configuration -->
  <log4net>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="100" />
      ...
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
      </parameter>
      <parameter>
        <parameterName value="@hostname" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout" value="%property" />
      </parameter>
      <parameter>
        <parameterName value="@app_domain" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout" value="%appdomain" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout" value="%thread" />
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout" value="%level" />
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout" value="%logger" />
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout" value="%message" />
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>
    <root>
      <level value="ERROR" />
      <appender-ref ref="AdoNetAppender" />
    </root>
  </log4net>
  <ServiceConfiguration>
    <!--database setting-->
    ...
    <!--report setting-->
    <ReportSettings noCrystalReport="False" printer="" labelPrinter="" />
    <!--device setting-->
    <DeviceSettings cashDrawer="" steriaLogLevel="0" />
    <!--app setting-->
    <ApplicationSettings debug="False" upgradeLevel="" disableSemiTransparency="False" backgroundColorStart="-9273198" backgroundColorEnd="-13880261" syncInterval="864000000" noCount="False" />
  </ServiceConfiguration>
</configuration>

当我改变这一行时:

<sessionState mode="Custom" customProvider="DefaultSessionProvider" timeout="15">

:

<sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="15">

它工作完美,但我需要使用会话发布到Windows Azure。

谁能帮助我或给我一些想法吗?

HttpException (0x80004005):会话数据太长

让我们从这部分开始:

当我改变这一行时:

<sessionState mode="Custom" customProvider="DefaultSessionProvider" timeout="15"> 

:

<sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="15">

它工作完美,但我需要使用会话发布到Windows Azure。

进程外会话状态必须序列化,以便它可以跨进程边界传播。例如,序列化可以将数据作为字节数组插入到SQL Server表中。

根据错误消息,您的对象图的序列化表示似乎有一个最大大小。此限制由特定提供商施加;其他ASP。网络提供商没有义务定义此限制。

经过一番研究,我确认确实存在一个限制。

在DefaultSessionStateProvider中,位于System.Web.Providers.dll中(是microsoft . asp.net . providers包的一部分):

this.MaxSessionSize = ConfigurationManager.AppSettings["maxSessionSize"] == null 
    ? 500000 
    : Convert.ToInt32(ConfigurationManager.AppSettings["maxSessionSize"], 
        (IFormatProvider) CultureInfo.InvariantCulture);

显示了大小(500000),以及如何更改它(Azure可能会对此施加额外的限制;我不知道)。

然而,有一个更大的问题:你真的需要在会话中存储这么多数据吗?繁重的训练通常不是个好主意。首先,想象一下为每个页面请求序列化/反序列化500000字节的对象图所引起的处理负载。

我想到的一个解决方案是对sessionState使用压缩:

<sessionState mode="Custom" customProvider="DefaultSessionProvider" compressionEnabled="true">