Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok guys, while I was waiting for some help I put my hands to work and I was able to find a good solution (in my opinion of course :P).</p> <p><strong>Let me share it with you:</strong></p> <p>So, I have one web application, or one console application, or some other kind of application, and lots of class library, and I need to store informations (different per Visual Studio project) that will change during runtime.</p> <p>Storing this information inside the <code>Web.config</code> or <code>App.config</code> is not a good idea for the many problems it takes.</p> <p>The other way I see it is to have one XML config file per project.</p> <p>Each application will read his own XML and add it to the Cache with <code>CacheDependency</code> (will expire when the XML config file is updated). This way we will not need to read the configuration all the times, and we also know when the configuration is changed.</p> <p><code>IMO THIS IS THE FASTEST AND EASIEST WAY TO SOLVE THE PROBLEM</code>, no need to use 3rd party frameworks (neither the time it takes to learn/program it).</p> <p>.</p> <h2>Example code:</h2> <pre><code> protected void Page_Load(object sender, EventArgs e) { DBConfiguration cachConf; cachConf = Cache["cachConf"] as DBConfiguration; if (cachConf == null) { cachConf = new DBConfiguration(); XmlDocument doc = new XmlDocument(); doc.Load(HttpContext.Current.Request.PhysicalApplicationPath + "bin/MyConf.xml"); XmlNodeList xnl = doc.GetElementsByTagName("username"); XmlElement xe = (XmlElement)xnl[0]; cachConf.Username = xe.InnerText.ToString(); xnl = doc.GetElementsByTagName("password"); xe = (XmlElement)xnl[0]; cachConf.Password = xe.InnerText.ToString(); Cache.Insert("cachConf", cachConf, new System.Web.Caching.CacheDependency( HttpContext.Current.Request.PhysicalApplicationPath + "MyConf.xml"), DateTime.Now.AddMinutes(60), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, new System.Web.Caching.CacheItemRemovedCallback( CacheItemRemovedCallBack)); } LabelUsername.Text = cachConf.Username; LabelPassword.Text = cachConf.Password; } private void CacheItemRemovedCallBack(string key, object value, CacheItemRemovedReason reason) { //Response.Write("Hello world"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload