IIS7: Custom response header goes missing after some hours or days

iis-7

This is driving me bananas.

We have multiple REST servers. We set a custom header in IIS so we can identify which server is responding to a request. Each server passes its name in this header.

On the IIS 6 servers, this works %100.
On IIS7, it works great… but after a few hrs or days, my custom header setting in IIS disappears.

I have custom bindings, and ssl, and all kinds of good stuff configured.

What could cause IIS to drop my custom header setting?

System is:

  • Win2008
  • IIS 7.0
  • Header name: X-APPSERVER-NAME
  • Using the inet manager gui application to make the change
    Just adding the header with the default value for local or server based setting

The sequence of events is:

  1. Go into IIS manager
  2. Go to your web site
  3. Add a custom header
  4. Test from fiddler, the new custom header is visible in the response
  5. Exit IIS Mgr,
  6. log out of windows
  7. Go home
  8. Go to bed
  9. Wake up
  10. Eat breakfast
  11. Go to work
  12. Discover the custom header is gone!
  13. Repeat Steps 1-12 a few times
  14. Post the issue here on server fault

thanks!!

Best Answer

By default, this gets written in your web.config file when adding a header with default values (local) in IIS7:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="X-Test" value="Test" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>

I believe IIS6 does it differently.

Do you have some kind of auto-deploy/auto-update of your website, which would overwrite such a changed web.config? (And thus deletes the custom header?)

Then either change your source web.config, or add the header on IIS Level (Root node) which is not written to the applications web.config