Handling configuration settings in asp.net web application

后端 未结 4 488
生来不讨喜
生来不讨喜 2021-01-14 07:42

I have a web application with over 200 configuration settings. These control everything from UI to Business logic.

Should these be retrieved on application startup o

4条回答
  •  伪装坚强ぢ
    2021-01-14 08:02

    I would retrieve it as needed. ASP.NET auto caches this data for you. It is not doing a file read each time. Try changing your web.config file while it's running and you will see that it kills all your sessions and effectively resets your app.

    Don't over complicate this. The intent of these settings in the web.config was to be used for settings across the entire application that you need to access. MS has provided you with the libraries to access them and has done the work to make that process as quick as possible. Maybe if you had thousands of settings or something you might be able to find a better caching algorithm but that would be a rare case.

    Spend your time on other parts of your code as there is not much to gain in changing how you access the web.config app settings.

    Update: If the settings are application wide then use the web.config. If they are user specific and stored in a DB then store them in the user's session at sign in. Some people say to use cookies for user specific settings but if you know who the user is then it is much better to use the session because it prevents a large cookie from being posted back to the server with every request from that user.

提交回复
热议问题