3

I created an HTTPModule that should log reauests and responses.
The parameters that tells the http module how to work located in the web.config.
But, in order to let the http module work with the latest values of the parameters, each request I read the parameters from the app.config.

Is there a way I can detect changes in the web.config so I can reload the http module parameters instead of reading them each time there is a response?

Naor
  • 23,465
  • 48
  • 152
  • 268

3 Answers3

7

You don't need to do that at all. You can load these properties only once and store them somewhere. Each time the web.config changes whole your ASP.NET application restarts and http module will have to initialize again.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • 1
    Yes, and also I think it's not doing parsing of the web.config file every time you request parameter value, but it's using the cached values (so basically, there's no performance hit on reading from ConfigurationManager against caching the values yourself) – veljkoz Jul 13 '11 at 09:40
  • that's simply not true. There is a multitude of ways where changing web.config will not terminate your app. I am troubleshooting one of those situations right now. – Sonic Soul May 17 '14 at 20:05
  • @LadislavMrnka I posted the details here http://stackoverflow.com/questions/23726529/httpapplication-does-not-quit – Sonic Soul May 18 '14 at 20:29
2

@Ladislav & @velijoz are correct. The web.config is read once and the values stored in memory until the app restarts, because the web.config was changed for example.

Unless of course you're opening and reading the file directly. That would be a bad thing.

If the settings change regularly, you could put them in another file, read the values and store them in the cache with a cache dependency on the file. That way you could change the settings without restarting your app everytime. when you change the settings file, the cache dependency would invalidate the cache and your code could read the file again.

Simon

Simon Halsey
  • 5,459
  • 1
  • 21
  • 32
0

what I have recently learnt is that when for example you change your web.config technically the asp.net application does not restart - it unloads. When you fire in the next request or start the app pool it then begins to load.

I'm filing this under a common misconception of asp.net developers ;)

user3086298
  • 290
  • 1
  • 4
  • 14