Class FileModule
A module serving files and directory listings from an IFileProvider.
Inherited Members
Namespace: EmbedIO.Files
Syntax
public class FileModule : WebModuleBase, IWebModuleImpl, IWebModule, IDisposable, IMimeTypeCustomizer, IMimeTypeProvider
Constructors
FileModule(String, IFileProvider)
Initializes a new instance of the FileModule class, using the specified cache.
Declaration
public FileModule(string baseRoute, IFileProvider provider)
Parameters
Type | Name | Description |
---|---|---|
String | baseRoute | The base route. |
IFileProvider | provider | An IFileProvider interface that provides access to actual files and directories. |
Fields
DefaultDocumentName
Default value for DefaultDocument.
Declaration
public const string DefaultDocumentName = "index.html"
Field Value
Type | Description |
---|---|
String |
Properties
Cache
Gets or sets the FileCache used by this module to store hashes and, optionally, file contents and rendered directory listings.
Declaration
public FileCache Cache { get; set; }
Property Value
Type | Description |
---|---|
FileCache |
ContentCaching
Gets or sets a value indicating whether this module caches the contents of files and directory listings.
Note that the actual representations of files are stored in FileCache;
thus, for example, if a file is always requested with an Accept-Encoding
of gzip
,
only the gzipped contents of the file will be cached.
Declaration
public bool ContentCaching { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
DefaultDocument
Gets or sets the name of the default document served, if it exists, instead of a directory listing when the path of a requested URL maps to a directory.
The default value for this property is the DefaultDocumentName constant.
Declaration
public string DefaultDocument { get; set; }
Property Value
Type | Description |
---|---|
String |
DefaultExtension
Gets or sets the default extension appended to requested URL paths that do not map to any file or directory. Defaults to null.
Declaration
public string DefaultExtension { get; set; }
Property Value
Type | Description |
---|---|
String |
DirectoryLister
Gets or sets the IDirectoryLister interface used to generate directory listing in this module.
A value of null (the default) disables the generation of directory listings.
Declaration
public IDirectoryLister DirectoryLister { get; set; }
Property Value
Type | Description |
---|---|
IDirectoryLister |
IsFinalHandler
Gets a value indicating whether processing of a request should stop after a module has handled it.
Declaration
public override bool IsFinalHandler { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
Remarks
If this property is true, a HTTP context's
SetHandled() method will be automatically called
immediately after after the
See Also
OnDirectoryNotListable
Gets or sets a FileRequestHandlerCallback that is called whenever the requested URL path has been mapped to a directory, but directory listing has been disabled by setting DirectoryLister to null.
The default is ThrowUnauthorized(IHttpContext, MappedResourceInfo).
Declaration
public FileRequestHandlerCallback OnDirectoryNotListable { get; set; }
Property Value
Type | Description |
---|---|
FileRequestHandlerCallback |
See Also
OnMappingFailed
Gets or sets a FileRequestHandlerCallback that is called whenever the requested URL path could not be mapped to any file or directory.
The default is ThrowNotFound(IHttpContext, MappedResourceInfo).
Declaration
public FileRequestHandlerCallback OnMappingFailed { get; set; }
Property Value
Type | Description |
---|---|
FileRequestHandlerCallback |
See Also
OnMethodNotAllowed
Gets or sets a FileRequestHandlerCallback that is called whenever
the requested URL path has been mapped to a file or directory, but the request's
HTTP method is neither GET
nor HEAD
.
The default is ThrowMethodNotAllowed(IHttpContext, MappedResourceInfo).
Declaration
public FileRequestHandlerCallback OnMethodNotAllowed { get; set; }
Property Value
Type | Description |
---|---|
FileRequestHandlerCallback |
See Also
Provider
Gets the IFileProviderinterface that provides access to actual files and directories served by this module.
Declaration
public IFileProvider Provider { get; }
Property Value
Type | Description |
---|---|
IFileProvider |
Methods
AddCustomMimeType(String, String)
Adds a custom association between a file extension and a MIME type.
Declaration
public void AddCustomMimeType(string extension, string mimeType)
Parameters
Type | Name | Description |
---|---|---|
String | extension | The file extension to associate to |
String | mimeType | The MIME type to associate to |
ClearCache()
Clears the part of Cache used by this module.
Declaration
public void ClearCache()
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Finalize()
Finalizes an instance of the FileModule class.
Declaration
protected void Finalize()
GetMimeType(String)
Gets the MIME type associated to a file extension.
Declaration
public string GetMimeType(string extension)
Parameters
Type | Name | Description |
---|---|---|
String | extension | The file extension for which a corresponding MIME type is wanted. |
Returns
Type | Description |
---|---|
String | The MIME type corresponding to |
OnBeforeLockConfiguration()
Declaration
protected override void OnBeforeLockConfiguration()
OnRequestAsync(IHttpContext)
Called to handle a request from a client.
Declaration
protected override Task OnRequestAsync(IHttpContext context)
Parameters
Type | Name | Description |
---|---|---|
IHttpContext | context | The context of the request being handled. |
Returns
Type | Description |
---|---|
Task | A |
Overrides
OnStart(CancellationToken)
Called when a module is started, immediately before locking the module's configuration.
Declaration
protected override void OnStart(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A |
Overrides
PreferCompression(String, Boolean)
Indicates whether to prefer compression when negotiating content encoding for a response with the specified content type, or whose content type is in the specified media range.
Declaration
public void PreferCompression(string mimeType, bool preferCompression)
Parameters
Type | Name | Description |
---|---|---|
String | mimeType | The MIME type or media range. |
Boolean | preferCompression | true to prefer compression; otherwise, false. |
TryDetermineCompression(String, out Boolean)
Attempts to determine whether compression should be preferred when negotiating content encoding for a response with the specified content type.
Declaration
public bool TryDetermineCompression(string mimeType, out bool preferCompression)
Parameters
Type | Name | Description |
---|---|---|
String | mimeType | The MIME type to check. |
Boolean | preferCompression | When this method returns true, a value indicating whether compression should be preferred. This parameter is passed uninitialized. |
Returns
Type | Description |
---|---|
Boolean | true if a value is found for |