tags:

views:

31

answers:

1

Hi,

I have method to compress file with GZip:

public static void CompressFile(string filePath)
{

      string compressedFilePath = Path.GetTempFileName();
      using (FileStream compressedFileStream = new FileStream(compressedFilePath, FileMode.Append, FileSystemRights.Write, FileShare.Write, BufferSize, FileOptions.None))
      {

        GZipStream gzipStream = new GZipStream(compressedFileStream, CompressionMode.Compress);
        using (FileStream uncompressedFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
          int offset = 0;
          while (true)
          {
            byte[] buffer = new byte[offset + BufferSize];
            int bytesRead = uncompressedFileStream.Read(buffer, offset, BufferSize);
            if (bytesRead == 0)
              break;

            gzipStream.Write(buffer, offset, bytesRead);
            offset += bytesRead;
          }
        }
        gzipStream.Close();
      }

      File.Delete(filePath);
      File.Move(compressedFilePath, filePath);
 }

My problem is, that on testing server (Win08 R2) it creates file and it can be downloaded via browser, but on webhosting server (older Win08 R1) it also creates file, but if i want to download it, access denied exception is thrown. Differences are in file permission. On R2 server has access to file Application pool identity (e.g. "MyWebSite"), but on R1 only IIS_IUSRS with "Special permission".

A: 

Ensure you have a MIME type added for the .gz extension in IIS configuration. I think this may cause the issue you are referring to.

Jakkwylde
yes i have this on both servers : .gz - application/x-gzip
Jan Remunda