首先出現的<sectionGroup name="dotnetnuke">裏面使用IConfigurationSectionHandle派生的類DotNetNuke.Framework.Providers命名空間下的ProviderConfigurationHandler進行自定義的控制,在web.config的後面使用了
<dotnetnuke></dotnetnuke>這個節,對於數據節,我們可以看到
<data defaultProvider="SqlDataProvider">
<providers>
<clear/>
<add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider" connectionStringName="SiteSqlServer" upgradeConnectionString="" providerPath="~/Providers/DataProviders/SqlDataProvider/" objectQualifier="dnn_" databaseOwner="dbo"/>
</providers>
</data>
這個data 是被以下代碼分析
public virtual object Create(object parent, object context, System.Xml.XmlNode node)
{
ProviderConfiguration objProviderConfiguration = new ProviderConfiguration();
objProviderConfiguration.LoadValuesFromConfigurationXml(node);
return objProviderConfiguration;
}
然後在ProviderConfiguration類中的以下代碼調用
internal void LoadValuesFromConfigurationXml(XmlNode node)
{
XmlAttributeCollection attributeCollection = node.Attributes;
_DefaultProvider = attributeCollection["defaultProvider"].Value;
foreach (XmlNode child in node.ChildNodes) {
if (child.Name == "providers") {
GetProviders(child);
}
}
}
internal void GetProviders(XmlNode node)
{
foreach (XmlNode Provider in node.ChildNodes) {
switch (Provider.Name) {
case "add":
Providers.Add(Provider.Attributes["name"].Value, new Provider(Provider.Attributes));
break;
case "remove":
Providers.Remove(Provider.Attributes["name"].Value);
break;
case "clear":
Providers.Clear();
break;
}
}
}
以上代碼對providers這個節點 裏面的數據進行了過濾,add,remove,clear ,保存了DefaultProvider,是通過xml 的atrribue屬性
當把配置節用hashtale保存好以後,在後面的模塊的數據庫開發中的類 class SqlDataProvider,可以看到
private ProviderConfiguration _providerConfiguration = ProviderConfiguration.GetProviderConfiguration(ProviderType);
ProviderType就是data節,得到providerConfiguration後就可以讀取屬性了