我正在使用AsyncFileUpload控件上傳圖像。 它從本地主機正常工作,但是當我將其上載到服務器時,出現以下錯誤。AsyncFileUpload SerializationException
我甚至不明白這個錯誤的原因。我會很感激任何答案。
這是我使用
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string email = WriteYourEmailTXT.Text;
var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).ToString("ddMMyyyy");
string parentFolder = Server.MapPath("uploads");
string childFolder = parentFolder + "\\" + email + "\\";
if (!Directory.Exists(childFolder))
Directory.CreateDirectory(childFolder);
string counter = getCount();
if (AsyncFileUpload1.HasFile) {
string ext = getExtension(AsyncFileUpload1.FileName);
string finalName = dt + "_" + counter + ext;
string finalPath = childFolder + finalName;
AsyncFileUpload1.SaveAs(finalPath);
SetCount();
SetFileName(finalName);
}
}
protected void SetCount()
{
HttpCookie aCookie = Request.Cookies["CountPhoto"];
int cookieNum = 0;
if (aCookie != null)
if (aCookie.Value != "")
cookieNum = int.Parse(aCookie.Value.ToString());
string newvalue = (cookieNum + 1).ToString();
Response.Cookies["CountPhoto"].Value = newvalue;
}
protected void SetFileName(string fileName)
{
HttpCookie aCookie = Request.Cookies["FileName"];
var filename = "";
if (aCookie != null)
if (aCookie.Value != "") {
filename = aCookie.Value;
}
string newFileName = filename + "," + fileName;
Response.Cookies["FileName"].Value = newFileName;
}
錯誤
無法序列化會話狀態的方法。 在「的StateServer」和「SQLServer的」模式, ASP.NET將序列化會話 狀態對象,並且作爲結果 非序列化的對象或 MarshalByRef對象不允許 。如果自定義會話狀態存儲庫 以「自定義」模式執行的類似序列化爲 ,則適用相同限制 。
堆棧跟蹤: [SerializationException:類型 'System.Web.HttpPostedFile' 在 大會 '的System.Web,版本= 2.0.0.0, 文化=中性 公鑰= b03f5f7f11d50a3a' 被 未標記爲序列化的。]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType 型)7733643個
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(類型 型,的StreamingContext上下文)258
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() 111 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(對象 OBJ,ISurrogateSelector surrogateSelector,的StreamingContext 上下文,SerObjectInfoInit serObjectInfoInit,IFormatterConverter來 轉換器,objectWriter objectWriter) 161 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(對象 OBJ,ISurrogateSelector surrogateSelector,的StreamingContext 上下文,serObjectInfoInit serObjectInfoInit,IFormatterConverter來 轉換器,objectWriter objectWriter) + 51 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(對象 圖表,部首[] inHeaders, __BinaryWriter serWriter,布爾FCHECK)410
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(流 serializationStream,對象圖, 部首[]標頭,布爾FCHECK)134 System.Web.Util.AltSerialization.WriteValueToStream(對象 值,的BinaryWriter作家)1577[HttpException(0X80004005):無法 序列化會話狀態。在 'StateServer'和'SQLServer'模式下, ASP。NET將序列化會話 狀態對象,並因此 不可序列化對象或 MarshalByRef對象不允許 。同樣的限制 適用,如果類似的序列化是 通過自定義會話狀態存儲在 「自定義」模式下完成。]
System.Web.Util.AltSerialization.WriteValueToStream(對象 價值的BinaryWriter作家)1662
系統。 Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(對象 價值的BinaryWriter作家)+34
System.Web.SessionState.SessionStateItemCollection.Serialize(的BinaryWriter 作家)606
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData 項目,溪流)+239
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData 項,的Int32 initialStreamSize,字節[] & BUF,的Int32 &長度)72
System.Web.SessionState.OutOfProcSessionStateStore.SetAndReleaseItemExclusive(HttpContext的 上下文,字符串ID , SessionStateStoreData項,對象 lockId,布爾的newitem)87
System.Web.SessionState.SessionStateModule.OnReleaseState(對象 源,EventArgs的EventArgs的)560
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep .Execute() +68 System.Web.HttpApplication.ExecuteStep(IExecutionStep 一步,布爾& completedSynchronously) +75
另外,您可以嘗試通過IIS配置切換Web服務器上的會話處理方式,但是我會猜測這是無法控制的。 – 2009-11-10 16:52:54
非常感謝您的回答。這非常有幫助。 – StrouMfios 2009-11-12 17:59:50