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="[email protected]" />
  <service2 isEnabled="true" emailAddress="[email protected]" />
  <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.

1

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.