我知道还有其他的话题,但都没有用。
在我的网页中,我允许下载一些配置文件。
我用的是这个代码:
public ActionResult DownloadConfigurationFiles()
{
var stream = this.HttpContext.GetSessionObj<byte[]>((int)WebVariable.ConfigurationFilesStream);
if (stream == null)
{
return HttpNotFound();
}
this.HttpContext.ClearSessionObj((int)WebVariable.ConfigurationFilesStream);
return File(stream, "application/x-7z-compressed", "ConfigurationFiles.7z"); // octet-stream
}它第一次工作得很好,当我几秒钟后再次尝试时,我下载了7z文件,但是当我想打开它时,我有以下错误:

当我进入代码时,它总是和第一次尝试相同,当它成功的时候.所以我不知道我的档案为什么腐败..?有任何方法来验证我们构建的存档是有效的7z文件吗?
发布于 2013-10-16 13:37:35
http://msdn.microsoft.com/en-us/magazine/cc301755.aspx
类似于数组-引用类型,您应该将字节复制到流中--例如,只有这样才能删除您的会话对象。
public ActionResult DownloadConfigurationFiles()
{
var bytes = this.HttpContext.GetSessionObj<byte[]>(idx_here);
if (bytes != null) // check existance
{
var target = new MemoryStream(bytes); // <-- don't use USING!
this.HttpContext.ClearSessionObj(idx_here);
return File(target, mime, file_name);
}
return HttpNotFound();
}我觉得这有帮助。
https://stackoverflow.com/questions/19402311
复制相似问题