Custom Configuration Sections in Location Tag

  • Thread starter Thread starter David Williams
  • Start date Start date
D

David Williams

I am familiar with creating custom configuration settings and accessing
them. However, for a current requirement, I need to control the various
settings in my custom configuration section by virtual location of the pages
accessing the configuration information. The best way that I know is to do
this via the use of the location tag in the web.config.

However, I can not seem to get the correct instance of the configuration
section in my configuration class. What is the correct method for
retrieving the current configuration based on the virtual location?

David
 
Hello David,

Could you explain in details what u mean with "virtual location" for config
files.
Did you try to create external config and refer to in from you main webconfig?!

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour
:: http://twitter.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


DW> I am familiar with creating custom configuration settings and
DW> accessing them. However, for a current requirement, I need to
DW> control the various settings in my custom configuration section by
DW> virtual location of the pages accessing the configuration
DW> information. The best way that I know is to do this via the use of
DW> the location tag in the web.config.
DW>
DW> However, I can not seem to get the correct instance of the
DW> configuration section in my configuration class. What is the
DW> correct method for retrieving the current configuration based on the
DW> virtual location?
DW>
DW> David
DW>
 
By virtual location I mean that in my web.config I need to set something
simular to this:

<configuration>
<configSections>
<add name='customSectionGroup" ...>
</configSections>
<customSectionGroup>
<customSection>
<customOption />
</customSection>
</customSectionGroup>
<location path="someVirtualDirectory">
<customSectionGroup>
<customSection>
<customOption />
</customSection>
</customSectionGroup>
</location>
</configuration>

Then in our web site, have the option(s) set in the <customSectionGroup> be
in effect all of the site save within ~/someVirtualDirectory, where I need
the option(s) in the <location><customSectionGroup> tag to be in effect.

I know how to write the code to read the default <customSectionGroup>.
However, getting the information from within the
<location><customSectionGroup> is currently baffling me.

I hope that this makes more sense.

David
 
David Williams said:
By virtual location I mean that in my web.config I need to set something
simular to this:

<configuration>
<configSections>
<add name='customSectionGroup" ...>
</configSections>
<customSectionGroup>
<customSection>
<customOption />
</customSection>
</customSectionGroup>
<location path="someVirtualDirectory">
<customSectionGroup>
<customSection>
<customOption />
</customSection>
</customSectionGroup>
</location>
</configuration>

Then in our web site, have the option(s) set in the <customSectionGroup>
be in effect all of the site save within ~/someVirtualDirectory, where I
need the option(s) in the <location><customSectionGroup> tag to be in
effect.

I know how to write the code to read the default <customSectionGroup>.
However, getting the information from within the
<location><customSectionGroup> is currently baffling me.

I hope that this makes more sense.

What's meant to happen is that when you look at that configuration section
from a page running under that location, then the page will see the combined
configuration data.

Keep in mind how web.config is hierarchical. The <location> element simply
substitutes for creating a separate web.config file within that folder. In
either case, the configuration elements are all merged together into one
logical configuration associated with each folder in the web application.
There will only be a single instance of the configuration section.
 
That is exactly what I expected. However, my testing seems to show that it
is not working that way. When I do a read of the configuration (using
System.Web.Configuration.OpenWebConfiguration) from "someVirtialDirectory",
I am still getting the information from the base location, not the specific
location.

David
 
Back
Top