Results 1 to 7 of 7

Thread: Customizing Web.Config

  1. #1

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Customizing Web.Config

    I am trying to add custom nodes to my web.config file and I am running into a few issues. It looks something like this:

    VB Code:
    1. <configuration>
    2.     <configSections>
    3.         <section name="MySection" type="MySectionHandler"/>
    4.     </configSections>
    5.  
    6.  
    7. <MySection>
    8. <CustomNode>1</CustomNode>
    9. <CustomNode>2</CustomNode>
    10. <CustomNode>3</CustomNode>
    11. <CustomNode>4</CustomNode>
    12. </MySection>
    13. ...
    14. </configuration>

    Then I have the code for mysectionhandler as follows:

    VB Code:
    1. Public Class MySectionHandler
    2.     Implements IConfigurationSectionHandler
    3.  
    4.     Public Function Create(ByVal parent As Object, ByVal configContext As Object, ByVal section As System.Xml.XmlNode) As Object Implements System.Configuration.IConfigurationSectionHandler.Create
    5.         Return "HELLO"
    6.     End Function
    7. End Class

    Finally, I have my code that trys to display the values:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         TextBox1.Text = ConfigurationSettings.GetConfig("MySection")
    3.  
    4.     End Sub

    I am getting an error on the Configuration.GetConfig line. The error I am getting is:

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Exception creating section handler.

    It and it highlights the <section name="MySection" type="MySectionHandler"/> line in the Web.Config file.

    Anyone seen this before, or can anyone offer any suggestions?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Customizing Web.Config

    Just a guess since this is an ASP.NET question...
    Dont you need a space before the escape char?

    VB Code:
    1. <section name="MySection" type="MySectionHandler"/>
    2.  
    3. <section name="MySection" type="MySectionHandler" />
    ???

    Also, is that the complete xml heirachy for your section?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Customizing Web.Config

    Thanks for the response Rob, but I figured it out. It actually requires the fully qualified name of the object to be created:

    <section name="MySection" type="webconfigtest.MySectionHandler,webconfigtest"/>

    I changed it and it works.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Customizing Web.Config

    Cool! Always good to learn something new. Thanks.

    Ps, now since you solved it yourself you need to give yourself a Rep. jk
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: Customizing Web.Config

    Hi Guys

    Sorry for extending this disucssion but I was looking for a similar solution but in a VB.NET application. Based on your sample <section name="MySection" type="webconfigtest.MySectionHandler,webconfigtest"/> it would appear that webconfigtest is a DLL. I am writing an executable, say vbtest.exe, and wanted to include the Section handler within the same application so I set my section entry as
    Code:
    <section name="MySection" type="MySectionHandler" />
    but I get an error while retrieving the section data.

    I would like to know if the customer section handler class should necessarily be in a seperate DLL?

    Thanks for your help.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  6. #6

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Customizing Web.Config

    It doesn't require a separate DLL, however it does require the full name of the object. It is probably ProjectName.Classname in the case of the class in your executable.

  7. #7
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    Re: Customizing Web.Config

    Thanks Negative0. It works. I tried
    VB Code:
    1. <section name="articlesVB" type="VBNetLab.CustomTagHandler, VBNetLab" />
    and it worked. So it would appear that the type part should be something like this:
    VB Code:
    1. type="Assembyname.ClassName, AssemblyName"
    where Assembly name is the name of the executable.


    Thanks
    Last edited by Mr.No; Aug 22nd, 2005 at 02:36 PM.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width