I was working on a project on Saturday when I ran into a problem. I spent a good four hours trying to find a solution for it. When I finally did I still am not sure why it works but works it does.
I was working on this web site that was written in .NET. I needed to dupe that site and make a new site in a sub directory. I made the subdirectory a virtual directory as I didn't want to make the new application conflict with the root site.
Well that didn't happen. Conflict it did. I was getting an error (similar to this) that one of my declarations in my web.config was already declared. The declaration was in the Configuration part of the config file.
I went and did a little research and found many other programmers just as frustrated that they were having the same issues. On their development machine it worked fine but when they put it onto the site it would throw this same sort of error. Turns out they develop the way they are advised too by creating a subdirectory for each project so they don't inherit from each other. But when they tried to put the files on the server one project was the root and one was the Virtual Directory. Bam!
I was able to recreate this error on my machine by setting the project that was the root on the site as the root on my development machine. I could at least try and debug it.
In my research I found that even though the app is in a virtual directory it STILL inherits from the root on up.
Basically the hierarchy starts with the machine.config -> machine web.config -> app web.config -> subdirectory web.config and so on.
Technically a virtual directory is a subdirectory but the point of making it a virtual directory is to separate the app from other apps in your site. This works for everything except web.config files. Why? Microsoft says this is a feature and not a bug...I on the other hand beg to differ. Here are some configuration scenarios Microsoft details they get into the virtual directory configuration at the bottom.
I finally got around the problem but it took some work. One of my class libraries in the project I created as a IConfigurationHandler and has set it up in the web.config but because both projects used different name spaced the declaration line was slightly different. I tried everything to try to override it. I read you could override the web.config by using <clear> or <remove> tags but then I found that the web.config schema doesn't allow those tags in the configuration element.
In the end I took the class file and made into it's own DLL and referenced it in both projects and the configuration element became identical in both projects allowing me to see the virtual directory without an error.
So does this “feature” still work like this in ASP.NET 2.0? I am told that Microsoft fixed this. But frankly I am not sure if it truly does or not. I do know there are more tags in the web.config to allow you to lock or override elements in the web.config. So until I see it for my own eyes it's a hope that it is fixed.
I haven't even touched how ASP.NET 2.0 and a ASP.NET 1.1 web.config files don't like each other...but I haven't gotten to that point yet.
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u