Home > Backend Development > C++ > How to Determine File Extension MIME Types in ASP.NET and Other Frameworks?

How to Determine File Extension MIME Types in ASP.NET and Other Frameworks?

Mary-Kate Olsen
Release: 2025-01-09 17:02:41
Original
200 people have browsed it

How to Determine File Extension MIME Types in ASP.NET and Other Frameworks?

Get the MIME type corresponding to the file extension

Problem Description

How to get the MIME type associated with a file extension?

Solution

ASP.NET and other frameworks

In ASP.NET Core, you have the following options:

  • new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType); (VNext only)
  • MimeTypes NuGet Package
  • MimeMappings files from the .NET Framework reference source

.NET Framework 4.5 and above

Use System.Web.MimeMapping.GetMimeMapping Method:

<code class="language-csharp">string mimeType = MimeMapping.GetMimeMapping(fileName);</code>
Copy after login

Custom mapping added (reflection)

To add a custom mapping (using reflection), call the following code (Note : private fields are used):

<code class="language-csharp">MimeMapping._mappingDictionary.AddMapping(string fileExtension, string mimeType)</code>
Copy after login

The above is the detailed content of How to Determine File Extension MIME Types in ASP.NET and Other Frameworks?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template