コード例 #1
0
 public Task Invoke(HtcHttpContext httpContext)
 {
     foreach (string fileName in _files)
     {
         if (fileName.Equals("/$internal"))
         {
             foreach (string fileName2 in httpContext.Site.Indexes)
             {
                 var    path2     = httpContext.Request.Path.Add(fileName2);
                 string extension = Path.GetExtension(path2);
                 var    fileInfo  = httpContext.Site.FileProvider.GetFileInfo(path2);
                 if (fileInfo.Exists && httpContext.Site.FileExtensions.TryGetValue(extension, out var extensionProcessor))
                 {
                     return(extensionProcessor.OnHttpExtensionProcess(_next, httpContext, path2, extension));
                 }
             }
         }
         var path = httpContext.Request.Path.Add(fileName);
         var staticFileContext = new StaticFileContext(httpContext, httpContext.Site.FileProvider, path);
         if (!staticFileContext.LookupFileInfo())
         {
             continue;
         }
         return(staticFileContext.ServeStaticFile(httpContext, _next));
     }
     return(_next(httpContext));
 }
コード例 #2
0
 public Task Invoke(HtcHttpContext httpContext)
 {
     foreach (string replaceName in _paths)
     {
         PathString fileName          = replaceName.Replace("$uri", httpContext.Request.Path.Value);
         var        staticFileContext = new StaticFileContext(httpContext, httpContext.Site.FileProvider, fileName);
         if (!staticFileContext.LookupFileInfo())
         {
             continue;
         }
         return(staticFileContext.ServeStaticFile(httpContext, _next));
     }
     return(_next(httpContext));
 }
コード例 #3
0
    private Task TryServeStaticFile(HttpContext context, string?contentType, PathString subPath)
    {
        var fileContext = new StaticFileContext(context, _options, _logger, _fileProvider, contentType, subPath);

        if (!fileContext.LookupFileInfo())
        {
            _logger.FileNotFound(fileContext.SubPath);
        }
        else
        {
            // If we get here, we can try to serve the file
            return(fileContext.ServeStaticFile(context, _next));
        }

        return(_next(context));
    }