FileExtensionContentTypeProvider Class

Provides a mapping between file extensions and MIME types.

Namespace
Microsoft.AspNetCore.StaticFiles
Assemblies
  • Microsoft.AspNetCore.StaticFiles

Syntax

public class FileExtensionContentTypeProvider : IContentTypeProvider
class Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider

Constructors

FileExtensionContentTypeProvider()

Creates a new provider with a set of default mappings.

public FileExtensionContentTypeProvider()
FileExtensionContentTypeProvider(System.Collections.Generic.IDictionary<System.String, System.String>)

Creates a lookup engine using the provided mapping. It is recommended that the IDictionary instance use StringComparer.OrdinalIgnoreCase.

public FileExtensionContentTypeProvider(IDictionary<string, string> mapping)

Properties

Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider.Mappings

The cross reference table of file extensions and content-types.

Return type:System.Collections.Generic.IDictionary<System.String>
public IDictionary<string, string> Mappings { get; }

Methods

TryGetContentType(System.String, out System.String)

Given a file path, determine the MIME type

Arguments:
  • subpath (System.String) – A file path
  • contentType (System.String) – The resulting MIME type
Return type:

System.Boolean

Returns:

True if MIME type could be determined

public bool TryGetContentType(string subpath, out string contentType)