473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Define a Regular Expresson within a Custom Configuration Section

I have a need to define a regular expression within a custom
configuration section. This can reside within a web.config or
other .config file.

Looking at the config below you can see the general Idea is to define
a uri then run a Regex against the response of a request to that uri.

The attached CustomConfigurationHandler is what I'm using to access
this config. The issue I have at the moment is how to access the CDATA
component of the pattern element. NB The code I've supplied actually
expects the pattern element to be a property of the the test element,
I've tried switching this around by making the pattern a
ConfigurationElement itself however this has result in the following
error:

"The configuration section cannot contain a CDATA or text element"

At the end of the day I'm open to any and all suggestions.

site.config

<configuration>
<configSections>
<section name="TestConfiguration"
type="SampleSite.Code.CustomConfiguration.SiteTest ConfigurationHandler,SampleSite"/
>
</configSections>
<TestConfiguration>
<test uri="http://www.test.com/">
<pattern><![CDATA[<title>(?<title>\w*)</title>]]></pattern>
</test>
<test uri="http://www.asp.net/">
<pattern><![CDATA[<title>(?<title>\w*)</title>]]></pattern>
</test>
</TestConfiguration>
</configuration>
SiteTestConfigurationHandler

namespace AutomatedWebRequestTool.Code.CustomConfiguration
{
public class SiteTestConfigurationHandler : ConfigurationSection
{
[ConfigurationProperty("", IsRequired=true, IsKey=false,
IsDefaultCollection=true)]
public SiteTestConfigurationElementCollection SiteTests
{
get { return base[""] as
SiteTestConfigurationElementCollection; }
set { base[""] = value; }
}
}

public class SiteTestConfigurationElement : ConfigurationElement
{
[ConfigurationProperty("uri", IsRequired = true,IsKey=true)]
public String Uri
{
get { return (String)this["uri"]; }
set { this["uri"] = value; }
}

[ConfigurationProperty("pattern", IsRequired = true, IsKey =
false)]
public string Pattern
{
get { return (string)this["pattern"]; }
set { this["pattern"] = value; }
}
}

public class SiteTestConfigurationElementCollection :
ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new SiteTestConfigurationElement();
}

protected override object GetElementKey(ConfigurationElement
element)
{
return ((SiteTestConfigurationElement)element).Uri;
}

protected override string ElementName
{
get
{
return "siteTest";
}
}

protected override bool IsElementName(string elementName)
{
return !String.IsNullOrEmpty(elementName) && elementName
== "siteTest";
}

public override ConfigurationElementCollectionType
CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMap;
}
}
public SiteTestConfigurationElement this[int index]
{
get
{
return base.BaseGet(index) as
SiteTestConfigurationElement;
}
}
}

}

Feb 4 '07 #1
0 2724

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

Similar topics

1
by: Thomas Koch | last post by:
Hi there - I have created my own implementation of System.Configuration.IConfigurationSectionHandler in order to have a special configuration section in an App.Config file that configures my...
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">...
3
by: rdcpro | last post by:
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...
4
by: jsh02_nova | last post by:
Why does a custom configuration handler type implementing IConfigurationSectionHandler can only be used on first level sections of the web.config? -- thx -jsh
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>...
0
by: branko.kannenberg | last post by:
Hi there, I want to use a custom configuration section of the following form (using the new .NET 2.0 classes, not the old IConfigurationSectionHandler interface): <mySection>...
0
by: style | last post by:
In the following sample I declared a custom configuration section within my app.config. As you can see, the lastName attribute of the second employee element is missing: <?xml version="1.0"...
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...
0
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.