简体   繁体   中英

Saving web configuration elements with events on controls

I've got some controls on a web page that surface configuration elements of my web application. I've wired up to their "OnChange" events, to capture value changes and so on. For each on change, I would like to say Configuration.Save(), but apart from getting "access denied" exceptions on web.config, I suspect this could be some weirdness, in trying to save to the configuration file for each control's onchange. Any suggestions for the best way to handle this?

Would you add some detail as to what type of settings you are trying to update? I really don't think you want to save changes to your web.config from the application. Does the application have a database you could tie your saves to? That seems more appropriate for a changes you would want to make regularly, and in a transaction safe manner.

I still think this is better done using a database. But, if you must, then I'd check out this guide to working with web.config .

From an architectural standpoint, it would be better to save the changes to the configuration file when the page is submitted. However, it is likely that the web.config file is locked when the application is started.

Consequently, if you have application-specific changes that you would like to save, it is better to find a method other than web.config for saving them.

You would want to find an alternative to modifying the web.config file directly. Doing so causes your application to restart. Either generate your own XML file or a database configuration set up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM