1

I have an ASP.NET MVC 5 app. My app has a web.config app. In this app, I have a custom section that looks like this:

<service.settings>
  <service1 isEnabled="true" emailAddress="someone@somewhere.com" />
  <service2 isEnabled="true" emailAddress="another@address.com" />
  <bonzai type="ficus" age="13" />
</service.settings>

My question is, how do I access these configuration values in my C# code? I'm familiar with ConfigurationManager.AppSettings. However, I'm not sure how to get configuration settings out of custom sections.

user70192
  • 13,786
  • 51
  • 160
  • 240
  • 1
    sounds like a possible duplicate of this possible duplicate http://stackoverflow.com/questions/7471234/how-to-create-a-custom-section-that-behaves-like-an-appsettings-section – JamieD77 Jul 08 '15 at 19:59

1 Answers1

1

You should use ConfigurationManager.GetSection(String)

// Assuming 'service.settings' is on the root of your web.config...
var yourSection = (YourSectionClass)ConfigurationManager
   .GetSection("service.settings")
Daniel
  • 8,655
  • 5
  • 60
  • 87
Claudio Redi
  • 67,454
  • 15
  • 130
  • 155