Inherited web.config ASP.NET 2.0

B

Ben

I have a group of settings that I'd like to have inherited by multiple
sites.

I'm trying this, but it's not working.

wwwroot\group\web.config
wwwroot\group\site1\web.config
wwwroot\group\site2\web.config

Where site1 & site2 are applications.

I have tried making group a subweb, an application and a subweb and
application. No matter what, site1 and site2 don't see the settings from
the group\web.config.

The funny thing is if I make my changes to wwwroot\web.config then site1 &
site2 see the changes. There is of course a catch, the changes are 2.0 and
the server is still running 1.1 sites so the 2.0 settings in the
wwwroot\web.config break all of the 1.1 sites :(

I'm open to any suggestions, thanks!

Ben
 
S

Steven Cheng[MSFT]

Hello Ben,

Welcome to the ASP.NET newsgroup.

From your description, you have hosted multiple ASP.NET 2.0 and 1.1 web
applications under a IIS website. And those ASP.NET 2.0 web applications
are under the same parent directory in the IIS virtual path. currently
you're trying to store some shared configuration info in the web.config
file within the parent directory of those ASP.NET 2.0 applications so that
they can automatically inherits the setting from them, correct?

Based on my understanding, such inheritance is naturally supported in
ASP.NET application(both 1.1 and 2.0). And the following MSDN document
describe the general rules of such configuration inheritance:

#ASP.NET Configuration File Hierarchy and Inheritance
http://msdn2.microsoft.com/en-us/library/ms178685.aspx

For your scenario, I think the problem may caused by the following things:

1. How are all the directories(from the IIS site root to the sub
application) created, through a physical sub directory or a mapped external
physical path? e.g. in your case, the complete path is "wwwroot\group\siteX"

Then, is the "group" directory a physical sub directory of "wwwroot"(site
root)? I've performed some local tests, and if the "group" folder is a
physical sub directory(not necessarily an application virtual directory),
the web.config setting in it will be inherited by any sub ASP.NET
applications under it(not matter through physical sub directory or a mapped
virtual directory poinetd to an external physical path).

2. What's the configuration sections are you going to share in the parent
web.config file? My local test use the "<connectionStrings> section as the
one to be inherited and it works well. Are you going to share the same
setting or any paricular configuration setting?

Anyway, please feel free to let me know if there is anything I've missed or
if there is any particular concerns in your scenario.

Looking forward to your update.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Ben,

How are you doing on this issue? Have you got any progress or still meet
any difficulties on this issue? If there is anything else we can help,
please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Ben

Steven,

Thanks for your reply. I haven't had any luck with this. The only way the
settings (connection strings) are inherited is if they are in the root of
the site.

inetpub\wwwroot\web.config - main
inetpub\wwwroot\group1\web.config - shared
inetpub\wwwroot\group1\site1
inetpub\wwwroot\group1\site2
inetpub\wwwroot\group1\site3

With the file structure above, if I put a connection string in the main
config file, site1, site2 and site3 see the connection string. If I remove
the connection string from the main config and place it in the shared
config, none of the sites see the setting.

Is what I'm doing something that should be working? I thought so, but it
isn't.

Thanks,
Ben
 
J

Juan T. Llibre

re:
With the file structure above, if I put a connection string in the main config file, site1, site2
and site3 see the connection string. If I remove the connection string from the main config and
place it in the shared config, none of the sites see the setting.
Is what I'm doing something that should be working?

No.

Root web.config settings are inherited, unless they are overturned
by a different setting in a web.config down the directory tree.

If you place a setting in inetpub\wwwroot\group1\web.config,
the setting will be local to the \group1 directory, but the
subdirectories below it will inherit from the root directory.

The reason for that is that \group1 is not an application.

If you want to have different settings in subdirectories, you must place
them in a web.config in the directories the different settings apply to.
 
J

Juan T. Llibre

re:
Juan, did you get the same results as Ben?

Hi, Steven.

My results are similar to yours for unconfigured directories down the tree.

I assumed that "inetpub\wwwroot\group1\site1" and the other two sites
( site2 and site3 ) were configured as separate applications.

Hence, the comment that they wouldn't inherit from /group1.

I stand by :
"Root web.config settings are inherited, unless they are overturned
by a different setting in a web.config down the directory tree."

And regret any confusion stemming from :
"If you place a setting in inetpub\wwwroot\group1\web.config,
the setting will be local to the \group1 directory, but the
subdirectories below it will inherit from the root directory."

What I meant to write was :
"If you place a setting in inetpub\wwwroot\group1\web.config,
the setting will be local to the \group1 directory, but the
subdirectories below it will inherit from their application's root directory."
( working on the assumption that the subdirectories are separate apps,
therefore they each have separate application roots, so they would *not*
inherit from a directory placed higher than them in the directory tree)





Steven Cheng said:
Hi Ben,

Thanks for the reply and thanks for Juan's inputs.

I don't think there is any difference between your test site and my local
test site's structure.

Juan, did you get the same results as Ben? I've tested this on my local
environment and web.config file inheritance does work as long as the
web.config is put in the parent folder that is in the folder path (to the
leaf application node).

I've attached a screenshot of my local test site's folder structure (in the
default IIS site):

The directory sturecture is

Default Site/
ASPNET/
V2/
WebSites/
.....web applications

Except the "Root Default Site" and the leaf web applications, all the other
directory in the hierarchy are normal virtual directory. I've put
web.config files(only contains some <appSetting> keys) in the following
directories:

*Default Site(root)

*V2

*WebSites

And in the web applications under "Websites", I can use the following code
to get all the appSetting keys defined in all the web.config files above:

=====================
protected void Page_Load(object sender, EventArgs e)
{
foreach (string key in WebConfigurationManager.AppSettings.Keys)
{
Response.Write("<br/>"+ key + ": " +
WebConfigurationManager.AppSettings[key]);
}
}
=====================

#Note, I haven't used any external mapped phyiscal directory for the above
virtual directories, they're all under the inetput/wwwroot. So the physical
direcotry structure is as below:

wwwroot\ASPNET\V2\WebSites\xxxweb applications dirs...

Is there anything different from your test applications? I'm using windows
2003 server/IIS6, ASP.NET 2.0

Please feel free to let me know if there is anything else you wonder or can
help you on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Juan T. Llibre

re:
Do you mean if the sub directories are configured as "application", they
won't inherit the web.config setting from their parent (no matter they're
physical sub dir or the parent virtual dir or not)?

Steven,

are you telling me that in this physical/virtual directory structure :

c:\inetpub\wwwroot -not an application
c:\inetpub\wwwroot\group1 - not an application
c:\inetpub\wwwroot\group1\site1 - IIS Application
c:\inetpub\wwwroot\group1\site2 - IIS Application
c:\inetpub\wwwroot\group1\site3 - IIS Application

....that site1, site2 and site3 will inherit from c:\inetpub\wwwroot 's
or c:\inetpub\wwwroot\group1 's web.config ?

*That* is the structure I was commenting on.

I *never* configure wwwroot as an application,
precisely because I don't want to run the risk of inheritance ambiguities.

I have always thought that Application roots are the topmost level
for web.config inheritance boundaries, unless the IIS Application is nested,
in which case, yes, the Application will inherit from its parent Application. .

Maybe I'm not understanding something about the scenario ?
 
S

Steven Cheng[MSFT]

Thanks for your quick reply Juan,

Yes, on my test server, the wwwroot is configured as "application" , and
this is the default setting after it is installed. Also, I've tested
removing the application(let it be a normal root virtual folder), and the
same result, sub web applications can still inhertis settings from all the
web.config files in the up level directorys(follow the virtual directory
tree).

As for the following statement;
===========================
I have always thought that Application roots are the topmost level
for web.config inheritance boundaries, unless the IIS Application is nested,
in which case, yes, the Application will inherit from its parent
Application. .
==========================

I think for those application specific states such as SessionState,
Appilcation State, this the case, however, web.config setting will inherit
up level web.configs in super directories(no matter application or not)
based on my understanding and testing.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Juan T. Llibre

Thanks for that heads-up, Steven.

I had been laboring under a mistaken assumption.

I just tested, changing the culture and uiCulture in the wwwroot and,
in spite of a test directory being configured as an application,
the culture setting *was* inherited from the root.

Thanks again.
 
S

Steven Cheng[MSFT]

Thanks Juan for your time,

So curerntly I'm still wondering the actual scenario of Ben's deployment
site and will wait for any further feedback. I think it important to make
this issue clear so that other guys won't suffer the problem any more.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Juan T. Llibre

re:
So currently I'm still wondering the actual scenario of Ben's deployment
site and will wait for any further feedback.

We haven't heard from him for 3 days now.
My curiosity is getting the best of me.

;-)

re:
I think it important to make this issue clear so that other guys won't suffer the problem any
more.

Agreed!
 
B

Ben

I apologize for my delayed response. My news reader wasn't showing any
activity in this thread, so I thought it ended with Juan saying it couldn't
be done. My directory structure is as follows...

c:\inetpub\wwwroot\web.config
c:\inetpub\wwwroot\aspnet20\web.config
c:\inetpub\wwwroot\aspnet20\site4\
c:\inetpub\wwwroot\aspnet20\site5\
c:\inetpub\wwwroot\aspnet20\site6\
c:\inetpub\wwwroot\aspnet11\site1\
c:\inetpub\wwwroot\aspnet11\site2\
c:\inetpub\wwwroot\aspnet11\site3\

Where each site* is configured as an application and virtual directory using
/site* as its' alias.

What we had been doing was storing shared configuration information in
c:\inetput\wwwroot\web.config. This allowed us to place a setting in the
root web.config for all of the 1.1 sites on the server to see. This was
working great, then we started working with the 2.0 sites. Some of the
configuration options from 2.0 cause web.config validation exceptions when a
1.1 site attempts to inherit the setting. I was hoping to be able to use an
inherited web.config file in the c:\inetpub\wwwroot\aspnet20 folder for
configuration inheritance down to any sub folders containing applications.
This just doesn't seem to be working out though. One of the main issues
here is connection string management. Our environment contains a
development server, staging server and a live server. Through the use of
inherited config files, we can make sure that dev always traces, shows
errors and points to the dev sql server while staging never traces or shows
errors and uses the staging database. Before inherited configuration files
people were publishing to staging, forgetting to update their config file to
change database, trace or custom error attributes and without knowing it
sites on staging were using the dev db etc.

Right now, we are doing something I don't like at all, we are placing shared
2.0 configuration information in the 2.0 machine.config...

Thanks,
Ben
 
S

Steven Cheng[MSFT]

Hi Ben,

Glad to hear from you.

I'm sorry to hear that you haven't got it work. Yes, I understand your
plan, since connectionStrings section is specific to v 2.0 only, you would
like to put it in a shared web.config under the root virtual directory of
the ASP.NET 2.0 applications and avoid the setting be inherited by 1.1
applciations.

My local test does follow the scenario you describs and that inheritance
works. I think there must still have some difference in our test
environment.

Anyway, if you would like to perform further investigation on this, please
feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top