0

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

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

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.

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.
            }
}

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

any idea ?

Nikhil Vaghela
  • 920
  • 2
  • 11
  • 36

2 Answers2

0

What I suspect here is that you have felt on session lock. What I mean is that the download and the generation and all this calls made using the session, and session locks everything until finish.

To solve this issue do two thinks.

  1. When you generate this file, generate it ether with thread ether with handle with out session needed
  2. Download this file from a handler (that not use session) and not from the page post back.

For example you make a handler, eg download.ashx and you make a link to your page as download.ashx?thisfileId=7723423&SecurityID=82jkj1288123 Inside your handler you read this parameters and you send the file. But if you make this on the page then a way is to disable the session for this page if you not use session, for example you set EnableSessionState="false" on the first line declarations.

Some similar questions and session relative answer.

call aspx page to return an image randomly slow

Replacing ASP.Net's session entirely

How to deliver big files in ASP.NET Response?

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • I am not sure i understand your suggestion, we are not using session explicitly anywhere in downloading the file. Can you please explain more in detail or point me to some relevant links ? – Nikhil Vaghela Mar 16 '12 at 09:19
  • @NikhilVaghela When you use a page, then the page call the session for the user, and this session is lock all the rest users until finish. So when you have a delay with a user, then the other user may get time out becuase the wait the first user to finish with that. I will place some links now on the answer. – Aristos Mar 16 '12 at 09:35
  • thanks for the help. Reason i thought my issue you described is something different then what you suggested is that the export of file was working from within the server and it was the issue when i was browsing the site from out side environment which obviously went thruogh load balancer. – Nikhil Vaghela Mar 22 '12 at 07:25
0

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.

Nikhil Vaghela
  • 920
  • 2
  • 11
  • 36