Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Export to Excel fails on Web Farm #9757


User avatar
0
ashvinu created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? 8.1.0
  • What is your product type (Angular or MVC)? MVC
  • What is product framework type (.net framework or .net core)? >net core

Hi,

we have deployed the application on a production environment which consists of a web farm, a load balancer and 2 IIS servers (windows server 2019). When trying to export results to Excel, I get an error that the file can't be found or does not exist.

Note that we also have a pre production environment with only 1 IIS server and no load balancer. And export to Excel works fine on this environment.

I think the the problem is that the file is being saved on a temp file cache.

Do you have any sample code on how to override this behaviour and save the file temporarily somewhere other than cache?

Thanks and Regards


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ashvinu

    Do you use Redis ? If not, you should switch to Redis, see https://aspnetboilerplate.com/Pages/Documents/Caching#redis-cache-integration. Default memory cache will cause problems in such an environment.

  • User Avatar
    0
    ashvinu created

    Hello, no we are not using Redis.

    I have tried using IDistributedCache.

    I haved added the following in the Startup.cs

       services.AddDistributedSqlServerCache(options =>
                {
                    options.ConnectionString = _appConfiguration["ConnectionStrings:Default"];
                    options.SchemaName = "dbo";
                    options.TableName = "CacheForTokens";
                });
    

    and have modified the TempFileCacheManager.cs as follows:

         public class TempFileCacheManager : ITempFileCacheManager
        {
            private readonly IDistributedCache _cacheManager;
    
            public TempFileCacheManager(IDistributedCache cacheManager)
            {
                _cacheManager = cacheManager;
            }
    
    
            public void SetFile(string token, byte[] content)
            {
                _cacheManager.Set(token, content);
    
            }
    
            public byte[] GetFile(string token)
            {
                return _cacheManager.Get(token) as byte[];
            }
        }
    

    I see that the token and value is saved successfully in the table when I try to export to Excel,

    but I am still getting the file not found error

    Do you have any idea about what is missing to get this working?

    Thanks and Regards

  • User Avatar
    0
    ashvinu created

    Hello,

    we figured out that the problem is actually with the direction server on the production environment.

    The redirection is not able to read after the "?" in the url, for example: https://website/File/DownloadTempFile?fileType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&fileToken=dd24ea6494374d4a8d5565e605eea86c&fileName=AuditLogs.xlsx

    We are trying to look for a solution, but just in case you have any idea, please let us know.

    Thanks and Regards

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ashvinu

    I'm not sure but maybe / charecter here application/vnd.openxmlformats-officedocument.spreadsheetml.sheet causes the problem. Could you encode query string values and try in that way ?

  • User Avatar
    0
    ashvinu created

    Hello,

    the infrastructure guy on our side managed to solve the problem with the redirection server and we are now able to download Excel using the IDistributedCache.

    Thanks and Regards Kirtee