Response.WriteFile函数失败,并给出了504网关超时 [英] Response.WriteFile function fails and gives 504 gateway time-out

查看:229
本文介绍了Response.WriteFile函数失败,并给出了504网关超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:结果
-SharePoint 2010基金会结果
-Claim基础的认证结果
-Execution在web.config中超时被设置为3600结果

Environment:
-SharePoint 2010 foundation
-Claim based authentication
-Execution time out in web.config is set to 3600

概述:结果
我们有我们连接到AD和SQL数据库来获取用户和他们的相关数据在Active Directory中的perticular组织单位(OU)的Excel导出功能。
我们有OU在AD会已在其1400的用户得到。我们使用的开和关XML生成Excel文件的正常工作,需时约11-14分钟,以产生以下路径上的服务器上的文件
C:\\的Inetpub \\ wwwroot的\\ WSS \\ VirtualDirectories \\ VirtualDirectyrName \\ EXCEL \\ FileName.xlsx

Overview:
We have an excel export functionality where we connect to AD and SQL databases to fetch Users and their related data for a perticular Organization Unit (OU)in Active Directory. We have on OU in AD which has got around 1400 users in it. We are using Open and Closed xml to generate excel file which works fine and takes about 11-14 minutes to generate a file on the server on following path C:\inetpub\wwwroot\wss\VirtualDirectories\VirtualDirectyrName\Excel\FileName.xlsx

立即生成一个文件后,我们下面的一段code的这会从服务器读取文件并转储输出蒸汽和presents为对话框的文件OPE保存在浏览器的最终用户。

Immediately after generating a file we have following piece of code which would read file from server and dump it on output steam and presents a file ope-save as dialog box in browser to end user.

问题描述:结果
当一个组织有较少的用户数量,它并不会超过5-6 minteus产生对服务器的文件,下面的一段code成功下载浏览器上的文件。但是,当上面提到OU,我们有1400用户reponse.writefile函数失败,并在浏览我们能看到浏览无法显示此网页(当小提琴手是在我们发现它给 - HTTP 504错误)。 Surpricingly如果我们执行从服务器本身这个出口(即浏览服务器上的网站),它的下载没有问题。

Problem Description:
When an Organization has less number of users and it does not take more than 5-6 minteus to generate the file on server, following piece of code successfully downloads the file on browser. But when for above mentioned OU where we have 1400 users the reponse.writefile function fails and in browse we get to see 'Browse can not display this web page' (when fiddler was on we found it gives - http 504 error). Surpricingly if we perform this export from the server itself (i.e browse the web site on server) it downloads without issue.

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也给出了相同的行为。

we dont see any error in ULS logs, event logs specific to this behavior. Please note , response.TransmitFile also gives same behaviour.

任何想法?

推荐答案

我想通了这个问题,这是在硬件负载平衡器空闲超时时间的问题,我们在这里使用的问题。在负载均衡器的默认值是0,这意味着11分我的文件生成正在采取比造成这个问题更长的时间。增加负载平衡器空闲超时问题似乎解决方案。

I figured out the issue, It was an issue with the Idle time out issue in the Hardware load balancer we where using. Default value in load balancer was 0 which meant 11 minutes and my file generation was taking longer than that which caused this issue. Increasing load balancer idle time out issue seems to be solutions.

这篇关于Response.WriteFile函数失败,并给出了504网关超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆