Custom Configuration Sections in Location Tag

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
 
M

Michael Nemtsev [MVP]

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>
 
D

David Williams

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
 
J

John Saunders

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.
 
D

David Williams

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
 

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,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top