Example #1
0
 public bool TryGetFileInfo(HttpContext context, out string contentType,
                            out IFileInfo fileInfo, out DateTimeOffset?lastModified, out EntityTagHeaderValue etag)
 {
     contentType = null;
     fileInfo    = null;
     if (context.UseMethods("GET", "HEAD") && context.TryGetSubPath(_options.RequestPath, out var subPath) &&
         _options.TryGetContentType(subPath, out contentType) &&
         _options.TryGetFileInfo(subPath, out fileInfo))
     {
         var  last     = fileInfo.LastModified;
         long eTagHash = last.ToFileTime() ^ fileInfo.Length;
         etag         = new EntityTagHeaderValue('\"' + Convert.ToString(eTagHash, 16) + '\"');
         lastModified = new DateTimeOffset(last.Year, last.Month, last.Day,
                                           last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime();
         return(true);
     }
     etag         = null;
     lastModified = null;
     return(false);
 }