473,498 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

configSections

Hi all

I added the following to my web.config immediately beneath the opening
<configuration> declaration of my ASP.NET V2 website:

<configSections>

<section name="urlrewrites" type="UrlRewrite" />

</configSections>

But when I try to add the following within the web.config section I get
errors listed below:

<urlrewrites>

<rule>

<url>/Users/(.*)/(.*)\.aspx</url>

<rewrite>/$2/User.aspx?UserName=$1</rewrite>

</rule>

</urlrewrites>

Error 45 Unrecognized configuration section system.web/urlrewrites.
D:\Data\MyEcoSpace\WebSite\web.config 22


Can someone please tell me why this is not working?

Thanks

Pete
Jun 18 '06 #1
6 1624
V
Hi,

As far as I remember (from .Net 1.1) you also need to specify the type
of the custom section, and if your type is not one of the pre-defined
type, then you need to specify a custom configuration section handler
in the config file (which of course you need to develop ).

Regards,
Vaibhav

Peter Morris [Droopy eyes software] wrote:
Hi all

I added the following to my web.config immediately beneath the opening
<configuration> declaration of my ASP.NET V2 website:

<configSections>

<section name="urlrewrites" type="UrlRewrite" />

</configSections>

But when I try to add the following within the web.config section I get
errors listed below:

<urlrewrites>

<rule>

<url>/Users/(.*)/(.*)\.aspx</url>

<rewrite>/$2/User.aspx?UserName=$1</rewrite>

</rule>

</urlrewrites>

Error 45 Unrecognized configuration section system.web/urlrewrites.
D:\Data\MyEcoSpace\WebSite\web.config 22


Can someone please tell me why this is not working?

Thanks

Pete


Jun 18 '06 #2
You've done about 10% of the work needed.

I have an example at
http://sholliday.spaces.msn.com/PersonalSpace.aspx 12/1/2005
the "Reflection" example.

You have to write up the object ("handler") which looks at the xml you put
in the config file.


"Peter Morris [Droopy eyes software]" <pete@NO_droopyeyes_SPAM.com> wrote in
message news:eL**************@TK2MSFTNGP04.phx.gbl...
Hi all

I added the following to my web.config immediately beneath the opening
<configuration> declaration of my ASP.NET V2 website:

<configSections>

<section name="urlrewrites" type="UrlRewrite" />

</configSections>

But when I try to add the following within the web.config section I get
errors listed below:

<urlrewrites>

<rule>

<url>/Users/(.*)/(.*)\.aspx</url>

<rewrite>/$2/User.aspx?UserName=$1</rewrite>

</rule>

</urlrewrites>

Error 45 Unrecognized configuration section system.web/urlrewrites.
D:\Data\MyEcoSpace\WebSite\web.config 22


Can someone please tell me why this is not working?

Thanks

Pete

Jun 18 '06 #3
Hi
You have to write up the object ("handler") which looks at the xml you put
in the config file.


That's what the "type" is in my XML
<section name="urlrewrites" type="UrlRewrite" />

UrlRewrite is the class that handles the section. It is a class within my
APP_CODE folder, it isn't wrapped in a namespace or anything. So have I
just declared it incorrectly? Could you tell me how to declare it properly?

Thanks

Pete
Jun 18 '06 #4
using System;
using System.Web;
using System.Xml;
using System.Xml.XPath;
using System.Configuration;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Xml.Xsl;
using System.Reflection;
using System.Runtime.CompilerServices;

public class UrlRewriter : IConfigurationSectionHandler
{
protected XmlNode _oRules = null;

protected UrlRewriter() { }

public string GetSubstitution(string zPath)
{
Regex oReg;

foreach (XmlNode oNode in _oRules.SelectNodes("rule"))
{
oReg = new Regex(oNode.SelectSingleNode("url/text()").Value);
Match oMatch = oReg.Match(zPath);

if (oMatch.Success)
{
return oReg.Replace(zPath,
oNode.SelectSingleNode("rewrite/text()").Value);
}
}

return zPath;
}

public static void Process()
{
UrlRewriter oRewriter =
(UrlRewriter)ConfigurationSettings.GetConfig("syst em.web/urlrewrites");
string zSubst =
oRewriter.GetSubstitution(HttpContext.Current.Requ est.Path);
if (zSubst.Length > 0)
{
HttpContext.Current.RewritePath(zSubst);
}
}

#region Implementation of IConfigurationSectionHandler
public object Create(object parent, object configContext, XmlNode
section)
{
_oRules = section;

// TODO: Compile all Regular Expressions

return this;
}
#endregion
}
Jun 18 '06 #5
One of mine looks like this:

<section name="EmailSettingsSectionName"
type="GranadaCoder.Email.Settings.EmailSmtpSetting sHandler,GranadaCoder.Emai
l.Settings" />

or .. if I put in what it is:

<section name="NameOfConfigSectionLaterInConfigFile"
type="MyAssemblyName.Namespace1.Namespace2.MyObjec tName,MyAssemblyName" />

Usually, "MyAssemblyName" is the same thing as MyAssembly.dll , but it
doesn't have to map like that.

Make sure you put in a break point IN
public object Create
somewhere..
Because my experience has been that you cannot "step into" the Create Method
from the outside.
(Microsoft is using reflection to instantiate your custom handler class)

Usually you find a bug or two inside the handler you need to weed out.


"Peter Morris [Droopy eyes software]" <pete@NO_droopyeyes_SPAM.com> wrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
using System;
using System.Web;
using System.Xml;
using System.Xml.XPath;
using System.Configuration;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Xml.Xsl;
using System.Reflection;
using System.Runtime.CompilerServices;

public class UrlRewriter : IConfigurationSectionHandler
{
protected XmlNode _oRules = null;

protected UrlRewriter() { }

public string GetSubstitution(string zPath)
{
Regex oReg;

foreach (XmlNode oNode in _oRules.SelectNodes("rule"))
{
oReg = new Regex(oNode.SelectSingleNode("url/text()").Value);
Match oMatch = oReg.Match(zPath);

if (oMatch.Success)
{
return oReg.Replace(zPath,
oNode.SelectSingleNode("rewrite/text()").Value);
}
}

return zPath;
}

public static void Process()
{
UrlRewriter oRewriter =
(UrlRewriter)ConfigurationSettings.GetConfig("syst em.web/urlrewrites");
string zSubst =
oRewriter.GetSubstitution(HttpContext.Current.Requ est.Path);
if (zSubst.Length > 0)
{
HttpContext.Current.RewritePath(zSubst);
}
}

#region Implementation of IConfigurationSectionHandler
public object Create(object parent, object configContext, XmlNode
section)
{
_oRules = section;

// TODO: Compile all Regular Expressions

return this;
}
#endregion
}

Jun 18 '06 #6
Hi Sloan

I compiled the handler into an assembly which I then registered in the GAC.
My reference in the web.config is now a strong one and I no longer get an
error about my web.config having errors.

I'd certainly prefer to just use a class within the web project!
<section name="EmailSettingsSectionName"
type="GranadaCoder.Email.Settings.EmailSmtpSetting sHandler,GranadaCoder.Emai
l.Settings" />


Is yours in a separate assembly then?
Jun 19 '06 #7

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

Similar topics

1
2542
by: Jaco De Villiers | last post by:
Hi, I have added the following group and section: <configSections> <section name="sampleSection" type="System.Configuration.SingleTagSectionHandler" /> <sectionGroup name="tilos.sdk">...
1
1266
by: Jaco de Villiers | last post by:
Hi, I have added the following group and section: <configSections> <section name="sampleSection" type="System.Configuration.SingleTagSectionHandler" /> <sectionGroup name="tilos.sdk">...
1
2082
by: eje | last post by:
I want to use configSections for applicationsettings but I get Exception creating section handler. My code in web.config: <configuration> <configSections> <sectionGroup...
3
2568
by: =?Utf-8?B?TUNN?= | last post by:
I have the following configSections in my web.config. Again, it's not clear to me what this is doing because I can delete the entire section and the application compiles and runs fine. Why do I...
7
6178
by: =?Utf-8?B?RXZl?= | last post by:
I have the following sections defined in my app.config file: <configSections> <section name="1" type="System.Configuration.DictionarySectionHandler" /> <section name="2"...
0
7167
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
7208
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
7379
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
5464
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,...
1
4915
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
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
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 ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.