【发布时间】:2010-12-15 02:59:25
【问题描述】:
我正在使用 AsyncFileUpload 控件来上传图像。 它在本地主机上运行良好,但是当我将其上传到服务器时出现以下错误。
我什至无法理解这个错误的原因。我会很感激任何答案。
这是我正在使用的方法
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, 文化=中性, PublicKeyToken=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 代理选择器,StreamingContext 上下文,SerObjectInfoInit serObjectInfoInit, IFormatterConverter 转换器,ObjectWriter objectWriter) +161 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(对象 obj,ISurrogateSelector 代理选择器,StreamingContext 上下文,SerObjectInfoInit serObjectInfoInit, IFormatterConverter 转换器,ObjectWriter objectWriter) +51 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(对象 图,Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +410
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(流 序列化流,对象图, 标头 [] 标头,布尔 fCheck) +134 System.Web.Util.AltSerialization.WriteValueToStream(对象 值,BinaryWriter 写入器)+1577[HttpException (0x80004005): 无法 序列化会话状态。在 'StateServer' 和 'SQLServer' 模式, ASP.NET 将序列化会话 状态对象,因此 不可序列化的对象或 MarshalByRef 对象不是 允许。相同的限制 如果类似的序列化是适用的 由自定义会话状态存储完成 在“自定义”模式下。]
System.Web.Util.AltSerialization.WriteValueToStream(对象 值,BinaryWriter 写入器)+1662
System.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 初始流大小,字节[]& 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 step, Boolean & completedSynchronously) +75
【问题讨论】:
标签: asp.net ajaxcontroltoolkit