无法序列化会话状态;部署ASP时出现错误.网的网站

本文关键字:错误 网站 ASP 序列化 会话状态 部署 | 更新日期: 2023-09-27 18:15:35

此代码在我的本地系统中运行良好,但在部署后访问站点时抛出以下错误。它的会话状态没有在应用程序的任何地方声明。请告诉我如何处理这件事。

无法序列化会话状态。在"StateServer"answers"SQLServer"模式下,ASP. sqlNET将序列化会话状态对象,因此不可序列化的对象或MarshalByRef对象是不允许的。如果在' custom '模式下由自定义会话状态存储完成类似的序列化,则适用相同的限制。描述:在执行当前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  

无法序列化会话状态;部署ASP时出现错误.网的网站

如果您部署到单个服务器,只需确保SessionMode设置为InProc。该设置可能在部署过程中丢失。

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

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

由于您正在使用进程外会话数据存储,这将要求您添加到session的任何类型都是Serializable。这意味着您不能将任何类添加到Session并期望它能够顺利工作。许多第三方类和BCL类是不可序列化的,因此不能直接使用。

这是因为您要么使用StateServer或Sql Server模式来存储会话对象和DataView是不可序列化的。而不是只是使用InProc状态服务器,如Henk建议,我宁愿只是把可序列化的对象在Session,如果你不想意外时,asp.net工作进程回收和所有的会话对象丢失。