473,465 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom configuration section handlers with Namespaces

Hi all,

I've been building a nifty deserializing configuration handler that I use in
conjunction with my web.config in an ASP.NET web app. This is working quite
well, but I'm planning on servicing a number of different web service
operations from a single application, and because it's all XML, I've been
scoping everything to a specific namespace targeting a specific application
(these are all InfoPath forms).

It seems that the GetConfig method can only refer to a node by it's
local-name:

ConfigurationSettings.GetConfig("AccountsInRole");

What I would like to do is pass in a namespaceURI as well, so that I can use
the same node local-name for a number of applications, each with their own
section. Like:

ConfigurationSettings.GetConfig("AccountsInRole",
"urn:schemas-rdcpro-com:infopath/application1");

While I can specify a namespace in my ConfigurationSectionHandler, and use
namespace-qualified nodes, I don't see a way to specify that externally (ie,
from the calling web app):

public class XmlSerializerSectionHandler : IConfigurationSectionHandler
{

public object Create(object parent, object configContext, XmlNode section)
{
XPathNavigator xmlNav = section.CreateNavigator();
XmlRootAttribute xmlRoot = new XmlRootAttribute();
// wish I could explicitly set the Namespace I want!
xmlRoot.Namespace = xmlNav.NamespaceURI;
xmlRoot.ElementName = (string) xmlNav.LocalName;
string typeName = (string) xmlNav.Evaluate("string(@type)");
Type myType = Type.GetType(typeName);
XmlSerializer sr = new XmlSerializer(myType,xmlRoot);
// This will be cast to the appropriate type in the calling code.
return sr.Deserialize(new XmlNodeReader(section));
}
}
Of course, I could make my configuration a little more general, and have
nested custom configuration sections like:

<FormSubmitService>
<Application1>
<AccountsInRole type="ApplicationRoles.Accounts, ApplicationRoles">
<!-- config info for App 1 here -->
</AccountsInRole>
</Application1>
<Application2>
<!-- config info for App 2 here -->
</Application2>

and get the right one with:

ConfigurationSettings.GetConfig("FormSubmitService/Application1/AccountsInRole");

But it seems a shame to have XML Namespaces, and not be able to use them!
;^)

Am I missing something here? How would I get a particular "AccountsInRole"
using an XML namespace?

Regards,
Mike Sharp
Nov 19 '05 #1
3 2794
Hi Mike,

Thanks for your posting. As for the namespace problem when fetching xml
config section in config file, this is caused by the internal search
mechanism of the .net 's System.Configuration.ConfigurationSettings class.
This class use a internal class called
System.Configuration.ConfigurationRecord to retreive the section specified
by the GetConfig(string sectionname) method's sectionname parameter.
Infact, the search just spilit the sectionname string into a string array
via the "/" flag , then recursively use XmlReader to search from the
confige file's xml document. It compare each found element's Qulified Name
with the one in the string Array. So if we specify namespace for our
configSection, it'll only compare the namespace prefix rather than the
namespaceURI. For example, if we have the following configSection:

<xs:root xmlns:xs="http://www.test.org">
.......
</xs:root>

We can locate the section via ConfigurationSettings.GetConfig("xs:root")

but the ConfigurationSettings.GetConfig("http://www.test.org:root") won't
work. Currently I think we could only do our custom xml parsing through the
means you mentiond:
1. Use general hierarchical sections

2. Put all the sub sections in a single root section(parsed by our custom
section handler). Then, we can differ the sub sections via namespaceURI

Thanks & Regards,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 19 '05 #2
Thanks Steven,

If you have a place for feature requests, it would be very nice if the
Configuration class was namespace-aware, so that there could be two sections
like:

<!-- App 1 -->
<myStuff xmlns="urn:schemas-rdcpro-com:App1">
<foo>bar</foo>
</myStuff>

<!-- App 2 -->
<myStuff xmlns="urn:schemas-rdcpro-com:App2">
<foo>snafu</foo>
</myStuff>

so that two similar applications, especially those built from a "framework"
that had similar configuration constructs could co-exist in a web.config. An
excellent example is a forms processing service based on InfoPath forms. I
might have a fairly large number of forms processed by the same endpoint, but
each form belongs to a different Business system, and therefore might have
different configuration requirements even though the configuration *schema*
is the same!

I would suggest this feature be implemented by an overload for GetConfig()
that would accept both a section name as well as a namespace, as in:
public static object GetConfig(
string sectionName
);

public static object GetConfig(
string qualifiedName,
string namespaceURI
);

Regards,
Mike Sharp

"Steven Cheng[MSFT]" wrote:
Hi Mike,

Thanks for your posting. As for the namespace problem when fetching xml
config section in config file, this is caused by the internal search
mechanism of the .net 's System.Configuration.ConfigurationSettings class.
This class use a internal class called
System.Configuration.ConfigurationRecord to retreive the section specified
by the GetConfig(string sectionname) method's sectionname parameter.
Infact, the search just spilit the sectionname string into a string array
via the "/" flag , then recursively use XmlReader to search from the
confige file's xml document. It compare each found element's Qulified Name
with the one in the string Array. So if we specify namespace for our
configSection, it'll only compare the namespace prefix rather than the
namespaceURI. For example, if we have the following configSection:

<xs:root xmlns:xs="http://www.test.org">
.......
</xs:root>

We can locate the section via ConfigurationSettings.GetConfig("xs:root")

but the ConfigurationSettings.GetConfig("http://www.test.org:root") won't
work. Currently I think we could only do our custom xml parsing through the
means you mentiond:
1. Use general hierarchical sections

2. Put all the sub sections in a single root section(parsed by our custom
section handler). Then, we can differ the sub sections via namespaceURI

Thanks & Regards,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3
Hi Mike,

Thanks for your followup. Yes, your suggestion about providing a further
override GetConfig method for retrieving namespaceURI based config section
really sounds great. Not sure whether our CLR guys will improve the
generally xml config file's manipulation in the next version. As we could
see , the WHIDBEY asp.net's web.config manipulation has been greatly
enhanced by adopting the feedback from many parnters and community members.
I think you can also submit your good request to our product feedback site:

http://lab.msdn.microsoft.com/produc...k/default.aspx

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Søren Lund | last post by:
Hello, I have implemented a custom config section handler by implementing the IConfigurationSectionHandler interface. I have registered this handler in web.config and everything works fine ......
4
by: Nick Gilbert | last post by:
Hi, I would like the ability to store the configuration settings for all versions of my site in a single web.config file by using different sections. Eg: <siteConfig> <machine name="XENON">...
2
by: murl | last post by:
Below is what i have as the custom section in the web.config file... <?xml version="1.0" encoding="utf-8" ?> <configuration> <!-- register local configuration handlers --> <configSections>...
6
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection"...
8
by: Mark A. Sam | last post by:
Hello I am working locally with Visual Web Developer 2005 Express. Before I even installed it, the information from Microsoft was that you could FTP it to a remote site and it should work. The...
1
by: npaulus | last post by:
Hi I am trying to experiment with a custom configuration section in app.config but it just doesnt work. app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections>...
7
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
3
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.