IIS 10 serve static file truncated if being written to

103 Views Asked by At

Using IIS 10 to serve a static XML file is causing the file to be occasionally truncated. There is a separate process that frequently rewrites the file using some C# code within another application in IIS on the same server. If there is a web request for the file at the same time as the file is being written, IIS will serve up a truncated file. This is happening often enough to be noticeable.

Some context:

  • The IIS logs show an HTTP 200 result.
  • The XML files we are testing are anywhere from 3 to 14MB in size.
  • The XML file is in a subdirectory under the inetpub/wwwroot folder.
  • The XML file is being served using StaticFileModule with the path *.xml.

I'm kinda surprised by this behavior. I would think that if the file is being written, Windows would wait until the file is complete?

The C# process that is writing the file is executing:

using (StreamWriter outfile = new StreamWriter(filePath, true)) { // Write stuff here }

0

There are 0 best solutions below