问题描述
我在 IIS 服务器上的 ASP.Net 应用程序中使用 Ajax 文件上传控件(Ajax 控件工具包)。可能有几十个用户同时上传文件(相隔几秒钟)。根据 AjaxFileUpload documentation,这些文件临时存储在服务器上,并在调用 e.DeleteTemporaryData();
时删除。如果多个用户同时尝试上传文档,则会将随机文件存储在数据库中的错误帐户中。调用 delete 方法似乎没有帮助。这是一个错误吗?如何防止数据不匹配?每个帐户都有一个唯一的帐号,文件被插入到 sql 数据库中。
protected void DocumentA_UploadComplete(object sender,AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
try
{
//static fields
if (!string.IsNullOrEmpty(appID))
{
applicationID = appID;
}
string ext = Path.GetExtension(e.FileName);
if (contenttype != String.Empty)
{
byte[] bytes = e.GetContents();
using (sqlCommand cmd = new sqlCommand("dbo.spUploadAttachments",ConnC.con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new sqlParameter()
{
ParameterName = "@ApplicationID",Value = applicationID
});
cmd.Parameters.Add(new sqlParameter()
{
ParameterName = "@FileName",Value = e.FileName
});
cmd.Parameters.Add(new sqlParameter()
{
ParameterName = "@FileContent",Value = bytes
});
ConnC.con.open();
cmd.ExecuteNonQuery();
ConnC.con.Close();
}
}
e.DeleteTemporaryData(); //Thought this would clear up the temp data and prevent mismatch but doesn't seem to help.
}
catch (Exception ex)
{
//exception logic here
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)