Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. custom sectionGroups in web.config?

custom sectionGroups in web.config?

Scheduled Pinned Locked Moved ASP.NET
csharphelpquestionworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EnkelIk
    wrote on last edited by
    #1

    Hi all. I have a webservice coded in c#. I would like to add some custom sectiongroups to the web.config file, and I manage to do so in a normal application (to the App.config file), but have run into problems with the system.web part of the web.config file. I try to declare system.web as another sectiongroup (as I have seen on some pages on the net) but the web.config file below gives me this error: "Section or group name 'sessionState' has already been defined" If I on the other hand does not declare sessionState (or some other "entry" in the system.web sectiongroup) I get this error when trying to consume the service "Could not load type System.Configuration.NameValueSectionHandler from assembly System.Web"

    A 1 Reply Last reply
    0
    • E EnkelIk

      Hi all. I have a webservice coded in c#. I would like to add some custom sectiongroups to the web.config file, and I manage to do so in a normal application (to the App.config file), but have run into problems with the system.web part of the web.config file. I try to declare system.web as another sectiongroup (as I have seen on some pages on the net) but the web.config file below gives me this error: "Section or group name 'sessionState' has already been defined" If I on the other hand does not declare sessionState (or some other "entry" in the system.web sectiongroup) I get this error when trying to consume the service "Could not load type System.Configuration.NameValueSectionHandler from assembly System.Web"

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      Hi, If you just want to do name/value collection, then why not use the <appsetting> tags, eg.

      <system.web>
      ...
      </system.web>

      <!-- Generic application settings -->
      <appSettings>
      <add key="MyKey" value="MyValue" />
      </appSettings>

      Then use the following to access them:

      System.Configuration.ConfigurationSettings.AppSettings["MyKey"]

      But to answer your question about Custom config handlers, you need to create an object that implements the IConfigurationSectionHandler interface, e.g.

      namespace MyCompany.MySystem.Web.MyProduct.Configuration.Custom
      {
      internal class CustomConfigHandler : IConfigurationSectionHandler
      {
      #region Custom Config Handler methods

      	public virtual object Create(Object parent, Object context, XmlNode node)
      	{
      		return new CustomConfig((CustomConfig)parent, node);
      	}
      
      	#endregion
      }
      
      public class CustomConfig
      {
      	internal CustomConfig(CustomConfig parent, XmlNode node)
      	{
      		// implement how you want to parse the XML config
      	}
                  // methods/properties to access information
                  // ...
                  // ...
                  // ...
      }
      

      }

      So the system calls our CustomConfigHandler object passing the XML contents of the config file, and it's up to us to parse this. I generally create an object (CustomConfig) that stores this XML and exposes methods/properties that the web application can call to get the details. The methods/properties simply perform SelectSingleNode(XPATH) on the stored XML to retrieve the details. This allows for a more complex config structure than simple name/value pairs, e.g. Here is a snippet of one of my custom config sections...

      <!-- Custom application configuration -->
      <osi.search.types>
      <Type name="VIF">
      < Provider type='CSV'>
      <Source>
      <!--
      [Location] can be either a filename or
      @fieldname, we the location will be determined
      from the value of the @fieldname supplied with
      the search
      -->
      <Location><![CDATA[@SearchLocalityName]]></Location>
      <Base><![CDATA[C:\\CSVs\\]]></Base>
      <SearchLocalityName>
      <!-- United Kingdom -->
      <Name value='AA01'>AA01.txt</Name>
      <Name value='United Kingdom'>AA01.txt</Name>
      <Name value='UK'>AA01.txt</Name>
      </SearchLocalityN

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups