How to use custom errors on IIS with ASP.NET

0

I have modified my web.config file in my asp.net web application so that I am showing a custom error page:

<configuration>
    <system.web>
       ...snip
        <customErrors mode="On" defaultRedirect="WebForms/ErrorPage.aspx">
          <error statusCode="404" redirect="WebForms/ErrorPageNotFound.aspx" />
        </customErrors>        
    </system.web>  
</configuration>

When I run the site on IIS I get the following error:

Error code: 0x800700b7
Config section 'system.web/customErrors' already defined. 
Sections must only appear once per config file. 
See the help topic <location> for exceptions 

Clearly I have some config hierarchy at play here but I don't know which file I need to look at (I have 276 web.config files on my machine) - can someone point me in the right direction.

When I find the file can I just rem out the top level customErrors section or is this going to cause an issue for other web applications on the same machine that don't have customErrors defined?

asp.net
visual-studio-2010
iis-7
webforms
web-config
asked on Stack Overflow Jul 25, 2012 by Matt Wilko • edited Jul 25, 2012 by Matt Wilko

1 Answer

1

That section should be modified on the root web.config

If you re receiving that error, maybe you have several web.config in sub-directories of your main application, you should start checking those to remove them

Clearly I have some config hierarchy at play here but I don't know which file I need to look at (I have 276 web.config files on my machine) - can someone point me in the right direction.

Why don't you simply use windows search to find documents containing the string customErrors

To enable Windows 7 advanced search:

http://answers.microsoft.com/en-us/windows/forum/windows_7-files/in-windows-7-i-want-to-search-for-all-files/aadfe1f1-4a33-406b-8e72-bb920efa4f30

Config files hierarchy

  1. Global machine. <windir>\Microsoft.NET\Framework\<ver>\Config\Machine.config
  2. Root Web config. <windir>\Microsoft.NET\Framework\<ver>\Config\Web.config
  3. Website. <wwwroot>\Web.config
  4. Web application. <wwwroot>|IIS Web Site path\<webapp>\Web.config
  5. Folder. <wwwroot>|IIS Web Site path\<webapp>\<dir>\Web.config
answered on Stack Overflow Jul 25, 2012 by Jupaol • edited Jul 25, 2012 by Jupaol

User contributions licensed under CC BY-SA 3.0