How to update a shared file in IIS and ASP.NET?

We are replacing the “old” web application (the original CodeCentral was written more than 10 years ago, now it runs under http://cc.embarcadero.com with more than 12.7 million serviced), which uses a cache file to download downloads. The web application manages this file cache.

The only tricky bit of using file-based downloads is updating the file, which can be used by another version. Back when I wrote the original version of CodeCentral Delphi CGI, I vaguely remind myself that I can rename an existing file, even if someone can download it by writing a new file with the correct name and eventually clearing the old file.

However, I can be delusional because this does not work with our current IIS 6 and ASP.NET 2.x or 3.x code. So, what we have done is something that is rather unpleasant, but ultimately works:

public static void FileCreate(Stream AStream, string AFileName, int AWaitInterval)
{
  DateTime until = DateTime.Now.AddSeconds(AWaitInterval);
  bool written = false;
  while (!written && (until > DateTime.Now))
  {
    try
    {
      using (FileStream fs = new FileStream(AFileName, FileMode.Create))
      {
        CopyStream(AStream, fs);
        written = true;
      }
    }
    catch (IOException)
    {
      Thread.Sleep(500);
    }
  }
}

I think we missed something simple, and there should be a better way to replace the file that is currently being downloaded through IIS and ASP.NET. There is?

+3
source share
2 answers

I think we will solve this with the following logic:

/ . "[id].zip", "[id] _ [modified].zip" , "[id].zip", .

, , "[id] _ [modified].zip" "[id].zip", , , , "[id].zip".

, , , , , , .

+2
, ?

, , .

, .

0

Source: https://habr.com/ru/post/1706940/


All Articles