0

In the web.config there is an array of items - only 2

More often than not it reads all the elements correcting in the automatic pool recycling (which seems to be daily).

Every so often, the array wont read all the elements.

I'm going to add another key so I've got a check on the number of items, but I'm not quite sure what to do about it when the problem occurs. To fix it, we recycle the application pool again, and that will re-read it, and generally get it correct.

The array is read from web.config by:

NameValueCollection nvcDbKeys = nvcDbKeys = NameValueCollection)ConfigurationManager.GetSection("MyArray");

With the array being a simple keyvalue

<MyArray>
  <add key="prod1" value="user1"/>
  <add key="prod2" value="user2"/>
  <add key="prod3" value="user3"/>
</MyArray>

The I enter into a for loop to store the values. This code is called the first time the web method is called as a static initiator.

I can throw an exception, but would prefer to force a re-read if the counter doesn't match the number of array entries.

Can I just re-read the array, or do I need to force an application pool recycle via code?

dcole
  • 317
  • 1
  • 4
  • 12

1 Answers1

0

Yes, You can modify the web.config file and read it's value without the needs of restarting App Pool. The details explanation and implementation has already been answered in this question.

However, Personally, I wouldn't write any code that has to be changed during run time in web.config file. If you change web.config, your changes will have no effect until the AppDomain is restarted.

Community
  • 1
  • 1
Benjamin
  • 3,499
  • 8
  • 44
  • 77
  • How would you reread the config if needed? Read it manually instead of via the NameValueCollection – dcole Mar 09 '17 at 06:31