50

I have a site that was built using Visual Studio 2010. When I upgraded to Visual Studio 2013, on some pages I would get an error that said:

Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.mp4'.

After some searching, I found a helpful post on a blog, but since the issue was a little different and I didn't find it on stackoverflow, I thought I'd post the question and answer here.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Eric Barr
  • 3,999
  • 5
  • 29
  • 42

5 Answers5

112

The issue was that when I switched to Visual Studio 2013, the web server used for debugging changed. Visual Studio 2013 uses IIS Express by default. Although Visual Studio 2010 SP1 supports IIS Express, my installation was still using the default Visual Studio Development server.

Like IIS 7, Visual Studio Development Server did not define the mp4 mime type by default, so that's why we had it explicitly added in the web.config, like this:

<system.webServer>
<staticContent>
  <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
</system.webServer>

IIS Express, on the other hand, is based on IIS 8, and IIS 8 defines the mp4 mime type, and many others, by default. So when the mimeMap is explicitly set in the web.config, it is considered a duplicate.

If you DO NOT need to support IIS 7 in your production environment, then you can just completely remove the mimeMap tag from the web.config. If you need to support BOTH IIS 7 and IIS 8, then you can use a remove tag for the mimeMap first and then set it again, like this:

<system.webServer>
<staticContent>
    <remove fileExtension=".mp4" />
    <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
</system.webServer>

In IIS 7 the removal will do nothing since it isn't already defined, but in IIS 8 it will remove the original so that the new one is not a duplicate. Thanks to Oliver Payen for his post on the IIS 7 and IIS 8 difference and the remove solution.

Eric Barr
  • 3,999
  • 5
  • 29
  • 42
16

Simply remove extension before add it.

<remove fileExtension=".mp4" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
Erçin Dedeoğlu
  • 4,950
  • 4
  • 49
  • 69
  • 2
    Grrrr... I got this issue (and most of my Angular controllers stopped loading) when I upgraded from VS2013 to VS2015. Adding this line fixed it. Thank you very much !! – Mike Gledhill Aug 21 '16 at 08:40
  • 1
    After updating Visual Studio 2019 to 16.4.2 I got a: HTTP Error 500.19 – Internal Server Error HRESULT: 0x800700b7 Microsofts Support page (https://support.microsoft.com/en-us/help/942055/http-error-500-19-error-when-you-open-an-iis-7-0-webpage) says to edit the applicationHost.config file, but the mentioned fix was NOT to be found within that page or file. Editing the web.config file and adding did the trick. Thanks a million. – Alex Jan 15 '20 at 02:18
2

In my case, I solved the problem just by removing the line that was doing duplicate stuff:

 <configuration>
    (...)
    <system.webServer>
        <staticContent>
            <!--mimeMap fileExtension=".json" mimeType="application/json" /-->
        </staticContent>
    </system.webServer>
 </configuration>
Pedro Reis
  • 1,587
  • 1
  • 19
  • 19
  • 1
    ... which is great if you don't have to deploy to IIS 7. @Pedro's solution works in IIS 8 and up (depending on the fileExtension). – Rap Jan 26 '17 at 22:28
1

I just wanted to add some additional info in case there are people like me out there who are fumbling around in the dark. I don't really do this kind of development and inherited a site that I had to move from IIS 7.5 to IIS 10. When I copy the folders to the new server, I got an error like above.

This was the old web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="text/plain" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
    </staticContent>
    <rewrite>
      <rules>
        <rule name="http fix" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Based on the info above, I removed this chunk of code:

<staticContent>
  <mimeMap fileExtension=".json" mimeType="text/plain" />
  <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>

And then all was well. The site came up and worked fine.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Samantha
  • 7
  • 1
0

go to %windir%\system32\inetsrv\config\applicationHost.config backup this file and open in notepad and find duplicate entry and remove this line