locked
Can web.config be used like regular xml? RRS feed

  • Question

  • User120938120 posted

    So what I'm thinking about is having a section in web.config that looks like regular xml.  Something like the following:

    <states>
        <state>
          GA
          <accessCode>333444</accessCode>
        </state>
        <state>
          FL
          <accessCode>222333</accessCode>
          <FBaccessCode>778899</FBaccessCode>
        </state>
      </states>

    Something like that, and then access it through the ConfigurationManager object in code somehow.

    Am I on the right track?  Is what I'm thinking of doable - maybe not exactly like I've outlined above but in a similar way?  Or am I completely off base?

    Any input appreciated!

    Thursday, March 8, 2018 10:08 PM

Answers

  • User283571144 posted

    Hi dolot314,

    As far as I know, we could extend ASP.NET configuration settings with XML configuration elements of your own.

    To do this, you create a custom configuration section handler

    . The handler must be a .NET Framework class that inherits from the System.Configuration.ConfigurationSection class.

    The section handler interprets and processes the settings that are defined in XML configuration elements in a specific section of a Web.config file.

    You could read and write these settings through the handler's properties.

    More details about how to implement custom configuration section handler, you could refer to below tutorial.

    https://msdn.microsoft.com/en-us/library/2tw134k3.aspx?f=255&MSPPError=-2147217396 

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 12, 2018 8:14 AM

All replies

  • User283571144 posted

    Hi dolot314,

    As far as I know, we could extend ASP.NET configuration settings with XML configuration elements of your own.

    To do this, you create a custom configuration section handler

    . The handler must be a .NET Framework class that inherits from the System.Configuration.ConfigurationSection class.

    The section handler interprets and processes the settings that are defined in XML configuration elements in a specific section of a Web.config file.

    You could read and write these settings through the handler's properties.

    More details about how to implement custom configuration section handler, you could refer to below tutorial.

    https://msdn.microsoft.com/en-us/library/2tw134k3.aspx?f=255&MSPPError=-2147217396 

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 12, 2018 8:14 AM
  • User120938120 posted

    Thanks for the response on that.  I'll take a look at this and do some research and see if it meets my needs.

    Tuesday, March 13, 2018 7:31 PM
  • User120938120 posted

    For reference for others who may read this thread, here's a couple more links that I found a little more helpful than the standard MS documentation:

    Creating Custom Configurations 

    and 

    how to add custom configuration settings for an asp.net application

    Wednesday, March 14, 2018 2:54 PM