12

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?

Community
  • 1
  • 1
Deane
  • 8,269
  • 12
  • 58
  • 108

5 Answers5

9

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
  • 186
  • 1
  • 8
1

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
  • 44,326
  • 9
  • 65
  • 80
1

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
  • 26,785
  • 5
  • 80
  • 117
  • "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 Apr 24 '09 at 16:39
  • 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 Apr 24 '09 at 17:44
  • 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 May 19 '09 at 22:15
1

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

Alan Jackson
  • 6,361
  • 2
  • 31
  • 32
0

I've just come across this issue in my work and my solution was to create a new website, instead of trying to nest my application under the existing website. I kept the domain mapping the same for the new application (i.e. www.mysite.com ) but changed the port number/mapping.

As a result I can use my new app on www.mysite.com:88 and didn't have to use a subdomain.

The caveat here is that my application is a web service so having to specify the port number in the URL was a possibility for me. It might not be an option for you but I thought I would post this incase it helps someone in my situation.

The <location path="." inheritInChildApplications="false"></location> solution wasn't an option for me as the inheritInChildApplications doesn't seem to exist before ASP.Net Framework 4.0?

NickGPS
  • 1,499
  • 14
  • 22