public Task Invoke(HttpContext context) { if (!string.IsNullOrEmpty(_options.FilePath)) { var file = new Microsoft.Extensions.FileProviders.Physical.PhysicalFileInfo( new System.IO.FileInfo(_options.FilePath)); context.Response.SendFileAsync(file); return(Task.CompletedTask); } else { return(Task.CompletedTask); } }
/// <summary> /// Locate a file at the given path by directly mapping path segments to physical directories. /// </summary> /// <param name="subpath">A path under the root directory</param> /// <returns>The file information. Caller must check <see cref="IFileInfo.Exists"/> property. </returns> public IFileInfo GetFileInfo(string subpath) { subpath = AdjustSubpath(subpath); if (string.IsNullOrEmpty(subpath) || PathUtils.HasInvalidPathChars(subpath)) { return(new NotFoundFileInfo(subpath)); } // Relative paths starting with leading slashes are okay subpath = subpath.TrimStart(PathSeparators); // Absolute paths not permitted. if (Path.IsPathRooted(subpath)) { return(new NotFoundFileInfo(subpath)); } var fullPath = GetFullPath(subpath); if (fullPath == null) { return(new NotFoundFileInfo(subpath)); } var fileInfo = new FileInfo(fullPath); if (FileSystemInfoHelper.IsExcluded(fileInfo, _filters)) { return(new NotFoundFileInfo(subpath)); } var info = new PhysicalFileInfo(fileInfo); return(info); }