IIS seems to think I have duplicate Custom Headers defined; complains about it

iisiis-7.5web.config

I am a software developer and I debug a website on my local machine in IIS 7.5. Recently I experienced problems with my machine that would not go away, so I backed up, formatted, resintalled Windows and my IDE, and set everything back up again.

After publishing my site to IIS, now I am greeted with a config error page that says: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'X-Frame-Options'.

If I look in the features view of IIS at Custom Headers I see that I have two custom headers defined X-Frame-Options and Strict-Transport-Security.

I do have that custom header defined in my web.config, and if I remove it the other custom header also causes the error only with regard to that header .

Having removed both entries, the site now loads, but I no longer have either of the custom headers.

Now is the Custom Headers Feature I have no custom headers.

Are custom headers defined somewhere else? Why does it think I have duplicates. Those key values (e.g. ) are only defined in the web.config once, no duplication.

Best Answer

Custom Headers can be added at each level: Server/Site/Application. If you have duplicate entries between levels that causes an issue. At application level you can remove the header before adding so as to take care of duplicates at higher levels. Something like this:

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="X-Frame-Options"/>
        <add name="X-Frame-Options" value="Strict-Transport-Security"/>
      </customHeaders>
    </httpProtocol>
</system.webServer>