我使用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,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a‘中的'System.Web.HttpPostedFile’类型未标记为可序列化。
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType类型) +7733643
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type类型,StreamingContext上下文) +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转换器,ObjectWriter objectWriter) +161个System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj,ISurrogateSelector surrogateSelector,StreamingContext context,SerObjectInfoInit serObjectInfoInit surrogateSelector转换器,StreamingContext objectWriter) +51图,en21#,,Boolean ) +410
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream,对象图,Header[]头,布尔fCheck) +134个System.Web.Util.AltSerialization.WriteValueToStream(Object值,BinaryWriter编写器) +1577
HttpException (0x80004005):无法序列化会话状态。在“StateServer”和“SQLServer”模式下,ASP.NET将序列化会话状态对象,因此不允许非序列化对象或MarshalByRef对象。如果自定义会话状态存储在“自定义”模式下执行类似的序列化,则同样的限制也适用。
System.Web.Util.AltSerialization.WriteValueToStream(Object值,BinaryWriter撰稿人) +1662
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object值,BinaryWriter撰稿人) +34
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter作者( +606 )
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData项,流) +239
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData项目,Int32 initialStreamSize,Byte[]& buf,Int32 32& length) +72
System.Web.SessionState.OutOfProcSessionStateStore.SetAndReleaseItemExclusive(HttpContext上下文,字符串id,SessionStateStoreData项,对象lockId,布尔newItem) +87
System.Web.SessionState.SessionStateModule.OnReleaseState(Object源,EventArgs eventArgs) +560
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,布尔& completedSynchronously) +75
发布于 2009-11-10 16:52:14
问题在于您的本地计算机和web服务器之间的IIS配置差异。
您的服务器似乎是通过使用StateServer (另一台PC处理内存中的大量用户数据)或使用您的server (数据库将用户对象存储在特殊表中)来处理会话的。为了将数据传输到状态服务器或数据库服务器,IIS将序列化会话信息以将其传输到其他服务器。基本上,这将获取给定对象的所有细节,并将其转换为XML,以便根据需要将对象“保存”和“加载”到/从内存中加载。
本例中的具体问题是“System.Web.HttpPostedFile”类不支持序列化。通常,这个问题发生在由我们自己的开发人员编写的类中,我们只需向类添加一个属性,但是在这里,问题似乎存在于.NET框架提供的类中。恐怕您需要找到解决这个问题的方法,比如编写自己的类或不使用这个类。
https://stackoverflow.com/questions/1709325
复制相似问题