1

Wondering if it's possible to override web.config custom errors on a per directory basis. I'm thinking not, but thought I'd ask.

Thanks,

Mark

mappingman
  • 123
  • 2
  • 13

2 Answers2

0

The most straight forward way would be to create the web config for each directory explicitly. They should 'roll up' from MachineConfig all the way to your lowest level directory.

Another post here on SO demonstrates how you might do this programmatically: https://stackoverflow.com/a/2260335/86860

Nate
  • 30,286
  • 23
  • 113
  • 184
  • I've already tried the web.config per directory method. The problem with this method that I am having is that the error details are not as informative as that of the site web.config. – mappingman Aug 23 '18 at 19:24
0

There is an out-of-box solution for your query.

This step-by-step article describes how to use ASP.NET to make application-specific and directory-specific configuration settings. The Web.config file resides in the root directory of an ASP.NET application. The Web.config file specifies configuration information that is specific to the application. You can also set configuration settings on a per-directory basis. There are two ways to do so:

• Distribute multiple Web.config files to directories in the application. Add a Web.config file in the ASP.NET application directory with settings that override settings in a higher-level Web.config file or in the system machine configuration (Machine.config) file.

• Add per-directory or per-file settings directly to the application Web.config file. This method uses a single Web.config file to turn on per-directory configuration settings. You can also use this method in the Machine.config file to force configuration settings on ASP.NET Web applications and then to stop Web.config files from overriding Machine.config settings.

You can get more details from here: https://support.microsoft.com/en-in/help/815174/how-to-make-application-and-directory-specific-configuration-settings

Community
  • 1
  • 1
dj079
  • 1,389
  • 8
  • 14
  • I've already tried the web.config per directory method. The problem with this method that I am having is that the error details are not as informative as that of the site web.config. – mappingman Aug 23 '18 at 19:21
  • @MarkMiller The error details depends on the custom page you decide. But in any case, there is a **second approach** which allows you to use single web.config and still target a particular application or directory. Check this out on the same article. https://support.microsoft.com/en-in/help/815174/how-to-make-application-and-directory-specific-configuration-settings#4 – dj079 Aug 24 '18 at 01:30
  • Thanks @dj79. I'll try it out. – mappingman Aug 24 '18 at 12:16