2011-11-23 71 views
2

此代码在我的本地系统中正常运行,但在部署后访问站点时会引发以下错误。会话状态不在应用程序中的任何位置声明。请帮助我解决这个问题。部署ASP.Net站点时出现“无法序列化会话状态”错误

无法序列化会话状态。在'StateServer'和'SQLServer'模式下,ASP.NET将序列化会话状态对象,因此不允许使用不可序列化的对象或MarshalByRef对象。如果自定义会话状态存储在“自定义”模式下进行类似的序列化,则适用相同的限制。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。

Exception Details: System.Web.HttpException: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. 

源错误:

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. 

堆栈跟踪:

[SerializationException: Type 'System.Data.DataView' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.] 
    System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +7736011 
    System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +258 
    System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +111 
    System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +161 
    System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +51 
    System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +410 
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +134 
    System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1577 

[HttpException (0x80004005): Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.] 
    System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1662 
    System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +34 
    System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +606 
    System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +239 
    System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length) +72 
    System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +116 
    System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +560 
    System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 

回答

3

如果部署在一台服务器,只要确保SessionMode设置为InProc方式。该设置在部署过程中可能丢失了。

当你想使用多个服务器时,你必须确保你放入Session的所有内容都是可序列化的。

从错误中,您现在在会话中存储System.Data.DataView。我不确定这是否明智。

0

由于您使用的是进程外会话数据存储,因此这需要您添加到会话的任何类型都是可序列化的。这意味着您无法向Session添加任何类,并期望它能顺利运行。许多第三方类和BCL类是不可序列化的,因此不能直接使用。

0

发生这种情况是因为您使用StateServer或Sql Server模式来存储Session对象,而DataView不可序列化。正如Henk所建议的那样,如果不想仅仅使用InProc状态服务器,而是希望将可序列化的对象放置在Session中,那么当您回收asp.net辅助进程并丢失所有Session对象时,您不会感到意外。