Search code examples
asp.netwcfsoapiis-7.5custom-errors

Is there a way to display custom error pages in IIS for only parts of a website?


I have a website that exposes regular web pages as well as a WCF webservice. Ideally the webpages should display custom error pages for status 500 (using httpError in web.config) while the web service throws soap errors.

Unfortunately the custom error pages for status 500 will also hide the soap errors with a custom error page.

Is there a way to enable custom error pages in IIS 7.5 for only parts of a website? (I can't put the web service in a separate site, it depends on runtime objects in the web pages.)


Solution

  • If all your webservice files are stored in a directory separate from the rest of the site, you can just put a new web.config file in that directory and set a <httpErrors> node there. This will override the settings in the root web.config

    If you don't have a clean separation between your normal URIs and your webservice URIs, you can use the location node in your root web.config e.g.:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <location path="service/foo.aspx">
            <system.webServer>
                <httpErrors>
                    <remove statusCode="502" subStatusCode="-1" />
                </httpErrors>
            </system.webServer>
        </location>
    </configuration>
    

    You can have as many of these location nodes as you need.