所以,这是交易。我有两个ASP.NET应用程序,它们都使用SQLServer会话状态管理。他们也使用相同的服务器。我在外部DLL中有一个自定义会话类,它完全实现了序列化,并且两个应用程序都引用了它。反过来,每个应用程序都有一个继承自DLL类的类,两个应用程序都使用各自的类作为会话状态。
现在,我想要完成的是,如果你想去另一个应用程序,它可以查看会话(它们都使用相同的会话密钥)并将那里的现有对象视为基础(一个从DLL),提取您需要的任何登录信息,然后用您自己的覆盖会话对象。不幸的是,当第二个应用程序试图读取会话时,它似乎找到第一个应用程序的DLL,当它找不到它时,它会引发异常。
我的逻辑是否有缺陷?
以下是一个例子:
// Global.asax of the 1st app
protected void Session_Start(object sender, EventArgs e)
{
Session.Add(
"UserSessionKey",
new FirstUserSession()); // FirstUserSession inherits from BaseUserSession
}
现在第二个申请:
// Global.asax of 2nd app
protected void Session_Start(object sender, EventArgs e)
{
if (Session["UserSessionKey"] != null)
{
BaseUserSession existing = (BaseUserSession)Session["UserSessionKey"];
SecondUserSession session = new SecondUserSession(); // This also inherits from BaseUserSession
session.Authenticated = existing.Authenticated;
session.Id = existing.Id;
session.Role = existing.Role;
Session.Add("UserSessionKey", session);
}
else
{
Session.Add("UserSessionKey", new SecondUserSession());
}
}
这是异常堆栈跟踪。在这种情况下,“MyCBC”是第一个应用程序的真实名称,“ASPTesting”是第二个应用程序。
[SerializationException: Unable to find assembly 'MyCBC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.] System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() +1871092 System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name) +7545734 System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) +120 System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) +52 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) +190 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum) +61 System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() +253 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +168 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +203 System.Web.Util.AltSerialization.ReadValueFromStream(BinaryReader reader) +788 System.Web.SessionState.SessionStateItemCollection.ReadValueFromStreamWithAssert() +55 System.Web.SessionState.SessionStateItemCollection.DeserializeItem(String name, Boolean check) +281 System.Web.SessionState.SessionStateItemCollection.get_Item(String name) +19 System.Web.SessionState.HttpSessionStateContainer.get_Item(String name) +13 System.Web.SessionState.HttpSessionState.get_Item(String name) +13 ASPTesting._Default.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\sarsstu\My Documents\Projects\Testing\ASPTesting\ASPTesting\Default.aspx.cs:20 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
提前感谢所有人。
答案 0 :(得分:1)
答案 1 :(得分:0)
exisiting不是baseusersession,它是作为baseusersession的第一个用户。因此,它可能会被强制转换回firstusersession,它只存在于mycbc程序集中。