Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What I would do is use the not so well-known ASP.NET <a href="http://msdn.microsoft.com/en-us/library/12s31dhy%28v=vs.80%29.aspx" rel="nofollow">Response.TransmitFile</a> method, as it's very fast (and possibly uses IIS kernel cache) and takes care of all header stuff. It is based on the Windows unmanaged <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms740565%28v=vs.85%29.aspx" rel="nofollow">TransmitFile</a> API.</p> <p>But to be able to use this API, you need a physical file to transfer. So here is a pseudo c# code that explain how to do this with a fictional myCacheFilePath physical file path. It also supports client caching possibilities. Of course, if you already have a file at hand, you don't need to create that cache:</p> <pre><code> if (!File.Exists(myCacheFilePath)) { LoadMyCache(...); // saves the file to disk. don't do this if your source is already a physical file (not stored in a db for example). } // we suppose user-agent (browser) cache is enabled // check appropriate If-Modified-Since header DateTime ifModifiedSince = DateTime.MaxValue; string ifm = context.Request.Headers["If-Modified-Since"]; if (!string.IsNullOrEmpty(ifm)) { try { ifModifiedSince = DateTime.Parse(ifm, DateTimeFormatInfo.InvariantInfo); } catch { // do nothing } // file has not changed, just send this information but truncate milliseconds if (ifModifiedSince == TruncateMilliseconds(File.GetLastWriteTime(myCacheFilePath))) { ResponseWriteNotModified(...); // HTTP 304 return; } } Response.ContentType = contentType; // set your file content type here Response.AddHeader("Last-Modified", File.GetLastWriteTimeUtc(myCacheFilePath).ToString("r", DateTimeFormatInfo.InvariantInfo)); // tell the client to cache that file // this API uses windows lower levels directly and is not memory/cpu intensive on Windows platform to send one file. It also caches files in the kernel. Response.TransmitFile(myCacheFilePath) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload