2

I created a custom http module and want to add this module to the web config. The web application is a project that contains several "sub applications". A sub application is just a folder, and within that folder it has its own web.config. I'm doing this so each application has its own application related contents.

Now I created a custom http module. When adding this to the root web.config, the module is working properly. When adding the http module config to the directory-level web.config (e.g. /Applications/MyApplication/web.config) the module is not initialized anymore.

This is the root config which is working fine.

<httpModules>
  <add name="MyFirstHttpModule" type="CustomModule.CustomModule,CustomModule" />
</httpModules>

Kindly help

1 Answer 1

1

ASP.net configuration already supports configuration inherance. You just have to add a new web.config in the specified folder.

ASP.NET website's Web.config is part of an inheritance chain. Your website's subfolders can have Web.config. This allows for setting general settings at the site level and overriding them when necessary. Any settings in the base Web.config that aren't overridden in the subfolder stay in effect, so the "child" Web.config can be pretty small. You can continue to nest them, so sub-sub-subfolders can get their own Web.config if needed.

A good example is the Web.config file in an ASP.NET MVC application's View folder which does things like preventing directly viewing the View templates

You can read more here.

If a request is received for a file in the SubDir1 directory that does not exist, ASP.NET begins to search the configuration hierarchy, starting at the most local Web.config file (which is located in the current directory, if it exists, or a parent directory). ASP.NET is searching for an error Element for customErrors (ASP.NET Settings Schema) element where the statusCode attribute equals "404". Once ASP.NET finds the configuration setting for the 404 error, the URL in the redirect attribute is returned as the response.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.