开发者

How I can write in appSetting in web.config file using ASP.NET?

I can easily read my appSetting in web.config file and then fill all keys and values in asp.net form. but I need to have initial setup for my web application how I can write in appSetting ? Is it the best way or not I have to store all of the keys in database which is better ? and How 开发者_如何学PythonI can implement this ? I need to add a key and edit a key or their value in appSetting config file.


Manipulating values in the web.config file is not recommend, because once a user tries to modify a value, all User sessions will be terminated.

An application domain will unload when any change occurs in the Machine.Config, Web.Config, or Global.asax.

Read ASP.NET Case Study: Lost session variables and appdomain recycles

If your keys are modifiable, then it is preferable to store it in DB.


How to create initial settings file?

You can do it in Visual Studio, either manually editing web.config file or using Settings UI of Visual Studio.

To use DB or config file for settings?

It depends on your requirements. If you have more than on instance of application and you want them to share the same settings you might want to have settings in DB. This way you will not have sync issues and subtle bugs when you update settings in one instance and another keeps using old settings.
If you update settings often, then DB settings might be a better idea too, because changes in web.config trigger application restart. If you have one instance and rarely change settings, it is easier to go with web.config file. Depending on the requirements you might end up with the mix of those two approaches.

How to implement DB settings?

You can have table with two string columns Name/Value, or you can have table with one row and as many columns as many settings you have. The second approach is more 'typed' approach as you can specify appropriate data type for each column separately.


It depends how big is the application.

If you have planned a rich back-end then using database as configurations storage is preferred. Of course this approach needs more work.

If there's some simple configurations and webmaster should change them manually, web.config is preferred since changing db is not so easy when all things should be done manually.

Don't bother about modifying web.config and loosing sessions. In practice, maintenance for a few minutes when application load is minimum is an acceptable approach (you see maintenance page frequently on stackoverflow and other famous ones)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜