代码之家  ›  专栏  ›  技术社区  ›  profanis

AsyncFileUpload序列化异常

  •  1
  • profanis  · 技术社区  · 16 年前

    我正在使用AsyncFileUpload控件上载图像。 它在localhost上运行良好,但当我将其上传到服务器上时,出现以下错误。

    我甚至不能理解这个错误的原因。如果有任何答复,我将不胜感激。

    这就是我正在使用的方法

    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对象不是 被允许同样的限制 如果需要类似的序列化,则适用 由自定义会话状态存储完成 在“自定义”模式下。

    [序列化异常:类型] 中的“System.Web.HttpPostedFile” 程序集'System.Web,版本=2.0.0.0, 文化=中立, 未标记为可序列化。]
    System.Runtime.Serialization.FormatterServices.InternalGetSerializationMembers(RuntimeType 类型)+7733643
    System.Runtime.Serialization.FormatterServices.GetSerializationMembers(类型 类型,StreamingContext)+258
    +111 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerializate(对象 obj,ISurrogateSelector 代理选择程序,StreamingContext 上下文,SeroObjectInfoinit 血清目标信息素 转换器,ObjectWriter(ObjectWriter) +161 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serializate(对象 obj,ISurrogateSelector 代理选择程序,StreamingContext 血清目标信息素 +51 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serializate(对象 图表,标题[]吸入装置, __二进制编写器serWriter,布尔fCheck)+410
    标题[]标题,布尔fCheck)+134 System.Web.Util.AltSerialization.WriteValueToStream(对象

    [HttpException(0x80004005):无法 序列化会话状态。在里面 ASP.NET将序列化会话 不可序列化的对象或 MarshalByRef对象不是 被允许同样的限制 如果需要类似的序列化,则适用 由自定义会话状态存储完成 在“自定义”模式下。]
    值,二进制编写器)+1662
    System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(对象 值,二进制编写器)+34
    作家)+606
    System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData
    项目,Int32 initialStreamSize,字节[]&
    System.Web.SessionState.OutOfProcSessionStateStore.SetAndReleaseItemExclusive(HttpContext 上下文,字符串id, lockId,布尔值newItem)+87
    System.Web.SessionState.SessionStateModule.OnReleaseState(对象
    System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 System.Web.HttpApplication.ExecuteTep(IExecutionStep +75

    1 回复  |  直到 9 年前
        1
  •  1
  •   Sonny Boy    16 年前

    问题在于本地计算机和web服务器的IIS配置不同。

    您的服务器似乎设置为使用StateServer(另一台PC处理内存中的大量用户数据)或SQL server(您的数据库将用户对象存储在特殊表中)来处理会话。为了将数据传输到状态服务器或数据库服务器,IIS将序列化会话信息以将其传输到其他服务器。基本上,这将获取给定对象的所有细节,并将其转换为XML,以便根据需要将对象“保存”到内存中或从内存中“加载”。

    推荐文章