views:

593

answers:

4

Is it possible to completely negate a web.config in a subfolder?

Obviously, I have a web.config in the root.

If I have a subfolder called "MyApp", can I write a bunch of code in there and have it run without any reference to the web.config at root? It would have its own web.config, and wouldn't even reference the "higher" web.config in root.

What I'm looking for is complete App isolation. I'd like to be able to write an app in a subfolder of an existing site, which ignores the entire web.config hierarchy above it -- the app would an island all to itself.

I know I can use the "clear" element, but is that the best way? Just put a "clear" under every top level element? Just wondering if there's another way.

Duplicate of Will a child application inherit from its parent web.config?

A: 

No. By design for shared hosting and simplicity sake.

IIS7 changes that a little by allowing the configs to be explicitly locked/unlocked.

Chad Grant
A: 

Yes, you have to clear those sections want to override. Thinking about it a bit more, this makes sense, as the only way to clear everything might make it very hard to work out what to clear it to. Clear normally resets everything, including the root web.configs in the web.configs and machine.config defined in the frameworks /config folder on your server.

Note that you'll also lose access to the /bin folder, /app_code folder, etc. This may or may not be what you want.

Whether you can create sub-applications with your host is another matter to consider as well.

Zhaph - Ben Duguid
"will have no knowledge of the parent app, neither it's web.config [...]" -- I don't think this is true. You can access appSettings from a parent Web config, modules still apply, etc. In fact, I've had to explicitly "remove" modules from higher web.configs.
Deane
Hmm, good point, I've just tested that, and you're right. That's news to me, I shall update my answer shortly.
Zhaph - Ben Duguid
Your explanation of why you can't completely abandon higher web.configs makes sense -- there are things at the machine.config level, for instance, and make the Web server go, so you need to clear them selectively.
Deane
A: 

It sounds more like you should create a virtual directory that is another application root entirely.

Alan Jackson
+5  A: 

On the web.config file in the root directory, wrap the <system.web> element with the following element: <location path="." inheritInChildApplications="false"></location>

Check out this link for a reference:

http://www.jaylee.org/post/2008/03/Prevent-ASPNET-webconfig-inheritance-and-inheritInChildApplications-attribute.aspx

Joe.Ingalls
Thanks a lot for this tip, Joe. It really helped me!
Marcin Rybacki