In this post, ghj mentioned a few problems about using ConfigurationSettings.AppSettings[""] in our web or windows forms applications.
The config files are only loaded when an application loads, so any changes in it will not take effect immediately.
For web application, asp.net restarts the application any time the config file changes, ghj think it doesn't matter, but I can't say that I agree with him, In fact, restarting the application has a couple of bad effects, i.e. the application loses its cache and session state.
For windows application, only one thing you can do is that prompte the user to reboot the application![]()
I found a solution to this problem, Just write a custom class that would give me access to a configuration file, Ok, Let's start it.
How to use this, All you have to do is provide an add node in either your app.config or web.config file that points to the config file you want to use.
The config files are only loaded when an application loads, so any changes in it will not take effect immediately.
For web application, asp.net restarts the application any time the config file changes, ghj think it doesn't matter, but I can't say that I agree with him, In fact, restarting the application has a couple of bad effects, i.e. the application loses its cache and session state.
For windows application, only one thing you can do is that prompte the user to reboot the application
I found a solution to this problem, Just write a custom class that would give me access to a configuration file, Ok, Let's start it.
using System; |
||
<configuration>Note : This file path is relative to the exe or dll that contains the class. If you were using this file in a web application, you'd have to use "..\my.config".
<appSettings>
<add key="configfile" value="my.config"/>
</appSettings>
</configuration>
浙公网安备 33010602011771号
Feedback
you can store your own items in a custom config file and use your own CacheDependency to monitor changes,but i never test:) 回复
Fengzhimei@Dot.Net引用了该文章,地址:http://www.cnblogs.com/fengzhimei/archive/2004/05/27/11780.aspx 回复
Path.GetDirectoryName(dllpath)
返回的是:
@"c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net files\testweb\02da89a5\6e4314f7\assembly\dl2\beeff702\089d3d91_b443c401"
而不是你需要的路径
应该为:
AppDomain.CurrentDomain.BaseDirectory
回复