【发布时间】:2012-03-22 15:26:05
【问题描述】:
环境:
-SharePoint 2010 基础
-基于声明的身份验证
-web.config 中的执行超时设置为 3600
概述:
我们有一个 Excel 导出功能,我们可以连接到 AD 和 SQL 数据库,以获取 Active Directory 中特定组织单位 (OU) 的用户及其相关数据。
我们在 AD 中的 OU 上有大约 1400 个用户。我们正在使用 Open and Closed xml 生成 excel 文件,该文件工作正常,大约需要 11-14 分钟才能在以下路径的服务器上生成文件
C:\inetpub\wwwroot\wss\VirtualDirectories\VirtualDirectyrName\Excel\FileName.xlsx
在生成文件后,我们立即有以下代码,该代码将从服务器读取文件并将其转储到输出流中,并在浏览器中向最终用户显示文件操作保存对话框。
问题描述:
当一个组织的用户数量较少并且在服务器上生成文件的时间不超过 5-6 minteus 时,以下代码会成功地将文件下载到浏览器上。但是,当我们有 1400 个用户的上述 OU 时,reponse.writefile 函数失败并且在浏览中我们看到“浏览无法显示此网页”(当 fiddler 打开时,我们发现它给出了 - http 504 错误)。令人惊讶的是,如果我们从服务器本身执行此导出(即浏览服务器上的网站),它会毫无问题地下载。
protected void lnkbtnDownloadFile_Click(object sender, EventArgs e)
{
String fileName = @"C:\inetpub\wwwroot\wss\VirtualDirectories\VirtualDirectyrName\Excel\540KBFileWhichFails.xlsx";
//File size is hardly ~500 KB
//Wait for around 12 minutes, to mimic a scenario of file generation which takes time on staging and prod. environment.
System.Threading.Thread.Sleep(720000);
try
{
if (fileName != "")
{
var file = new FileInfo(fileName);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
Response.Write("This file does not exist.");
}
}
catch (Exception ex)
{
//This would usually give thread aboart exception but thats expected.
}
}
我们在 ULS 日志和特定于此行为的事件日志中看不到任何错误。 请注意,response.TransmitFile 也给出了相同的行为。
有什么想法吗?
【问题讨论】: