Here is the ConfigurationSection class
using System.Configuration;
namespace CampusWebStore.Config
{
public class PoolerConfig : ConfigurationSection
{
[ConfigurationProperty("PoolId", IsRequired = true)]
public string PoolId { get; set; }
[ConfigurationProperty("Host", IsRequired = true)]
public string Host { get; set; }
[ConfigurationProperty("Port", IsRequired = true)]
public int Port { get; set; }
[ConfigurationProperty("Enabled", IsRequired = true)]
public bool Enabled { get; set; }
}
}
The web.config section definition
<section name="PoolerConfig" type="CampusWebStore.Config.PoolerConfig, CampusWebStore"/>
The actual section
<PoolerConfig
PoolId="asdf-asdf-asdf-asdf"
Host="localhost"
Port="5000"
Enabled="true"
/>
And then the line that loads it (in Global.asax.cs)
PoolerConfig poolerConfig = ConfigurationManager.GetSection("PoolerConfig") as PoolerConfig;
It seems that no matter what I do, all the properties in my PoolerConfig are default values (null strings, 0 ints, etc). Research indicates this should be easy as pie, but to no avail I cannot figure this out.
You cannot use get/set
backers for configuration properties. You must access the base class to manipulate the properties. See http://msdn.microsoft.com/en-us/library/2tw134k3(v=vs.100).aspx for an example.
Change:
[ConfigurationProperty("PoolId", IsRequired = true)]
public string PoolId { get; set; }
To:
[ConfigurationProperty("PoolId", IsRequired = true)]
public string PoolId
{
get { return (string)this["PoolID"]; }
set { this["PoolID"] = value; }
}
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.