How to tell if web.config item is/is not inherited

B

Brad

Probably a very basic questions here:
When using code to look at a web.config item, how can I tell if the value
is/is not inherited? I have some common code that needs to iterate through
settings like appsettings and connectionstrings but I only want to look at
settings for the current web app: I would like to ignore a value if it
comes from a web.config up the folder heirarchy....it does not exist in the
current web apps web.config. And I do not want a developer to have to use a
Remove element to exclude the value just so the code can work.

Using .Net 2

Thanks

Brad
 
W

Walter Wang [MSFT]

Hi Brad,

Based on my understanding, you're using
WebConfigurationManager.OpenConfiguration() to read from web.config, you
noticed that appSettings and connectionStrings in the Configuration object
contain both settings inherited from parent web.config and settings in
itself. You want to know is it possible to differentiate them or only get
those settings in itself. Please correct me if I've misunderstood anything.

I've done some researching and looked into the WebConfigurationManager's
source code using Reflector (http://www.aisto.com/roeder/dotnet/),
unfortunately it seems not possible to only return a Configuration object
with settings from the web.config itself in current .NET framework version.
Your objective is a reasonable one and we're sorry for the inconvenience
caused. I will make sure your feedback gets forwarded to product team.

For now, I'm afraid you will have to read the web.config yourself to
determine which appsettings or connectionstrings are in it. I can give
further suggestion if you could elaborate more about your objective. Thanks.

In the meanwhile, you're also welcome to submit your feedback at
http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220 which
is monitored by our product team directly. Thanks again for your feedback.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

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

Brad

Thank you for the information. I can just examine the web.config as an
xmldocument.

Brad
 
W

Walter Wang [MSFT]

Hi Brad,

Thanks for your understanding. Please feel free to let me know if there's
anything else I can help.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top