one of the DNN learning notes configuration
Create Person: Pblee
Create Practice: 2006-6-28
Document name: DNN Learning Notes 1
Keywords: DNN source analysis Configuration
DNN is an open platform, not just the source code, which supports all user-defined components and hooks up to the main engine. Because of its open nature, its users are growing.
This learning note is based on the dnn 4.3 source code, which uses. NET Framework 2.0, so that you can learn the new features of. NET 2.0 while you're learning it.
Start with the configuration file first
Code Snippet 1 Release.config
< configsections >
< sectiongroup name = "DotNetNuke" >
<!--the requirepermission would cause a syntax warning-please ignore-it is required for Medium trust SUP Port-->
< section name = "Data" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Logging" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "scheduling" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "HtmlEditor" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Navigationcontrol" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Searchindex" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Searchdatastore" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Friendlyurl" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Caching" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Authentication" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = ' Members ' requirepermission = ' false ' type = ' DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Roles" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
< section name = "Profiles" requirepermission = "false" type = " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
</sectiongroup >
</configsections >
The explanation for the configsessions element MSDN2003 is not deep
[Reference: Ms-help://ms. Msdnqtr.2003feb.2052/cpgenref/html/gngrfconfigsectionselementcontainertag.htm]
Note
If this element is in a configuration file, it must be the first child element of the <configuration> element.
[end of reference]
MSDN2005 's explanation:
[Reference: Ms-help://ms. Msdnqtr.v80.chs/ms. Msdn.v80/ms. Netdevfx.v20.chs/dv_aspnetgenref/html/8a5cbc84-0257-4c2e-80a9-a064fe7c896b.htm]
Specify configuration sections and namespace declarations.
<configSections>
<section/>
<sectiongroup/>
<remove/>
<clear/>
</configSections>
Child elements
Element description
Clear
Removes all references to inherited sections and section groups, allowing only sections and section groups that are added by the current section and sectiongroup elements.
Remove
Removes a reference to an inherited section and section group.
Section
Defines the association between a configuration section handler and a configuration element.
Sectiongroup
Defines an association between a configuration section handler and a configuration section.
Note
The configsections element specifies the configuration section and handler declaration. This is necessary because ASP.net does not make any assumptions about how to handle the settings in the configuration file. However, ASP.net will delegate the processing of configuration data to the configuration section handler.
Each section element identifies a configuration node or element and an associated ConfigurationSection derived class that handles the configuration section or element. Section elements can be logically grouped in the sectiongroup element to organize the section elements and to avoid naming conflicts. The section and sectiongroup elements are contained within the configsections element.
If the configuration file contains a configsections element, the configsections element must be the first child element of the configuration element.
[end of reference]
Open the Machine.config file to see the definitions of some of our commonly used sections, such as:
Code Snippets 2 Machine.config < configsections >
< section name = "AppSettings" type = "System.Configuration.AppSettingsSection, System.Configuration, version= 2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a "restartonexternalchanges = false" Requirepermission = " False "/>
< section name = "connectionstrings" type = "System.Configuration.ConnectionStringsSection, System.Configuration, version=2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a "requirepermission = false"/>
< sectiongroup name = "system.web" type = "System.Web.Configuration.SystemWebSectionGroup, system.web, version= 2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a ">
< section name = "anonymousidentification" type = "System.Web.Configuration.AnonymousIdentificationSection, System.Web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a "allowdefinition =" MachineToApplication "/>
< section name = "Authentication" type = "System.Web.Configuration.AuthenticationSection, system.web, version= 2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a "allowdefinition = MachineToApplication"/>
...... Omit a paragraph ...
</sectiongroup >
That is to say, the config file is the most important place is configsections, without it we configure the things the program does not know how to deal with. Do an experiment.
Create a new Web project and add the following code to the <configuration> element of the default generated web.config.
Sample Code 1.1 < appSettings >
< add key = "ServerName" value = "WWW.GOOGLE.COM"/>
</appSettings >
Then add the following code to the page Page_Load ():
Example code 1.2
protected void Page_Load (object sender, EventArgs e)
{
Response.Write (system.configuration.configurationsettings.appsettings["ServerName"]);
}
Browsing the page, very simple, we see the configuration of the content, "WWW.GOOGLE.COM", this is believed that many people have been used
Below we do a little damage, delete the definition of <appSettings> in Machine.config
< section name = "AppSettings" type = "System.Configuration.AppSettingsSection, System.Configuration, version= 2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a "restartonexternalchanges = false" Requirepermission = " False "/>
Note # before deleting to ensure that the source file has been backed up, we still need to change it back.
Save Machine.config, then refresh just the page, there are errors:
Configuration error
Description: An error occurred while processing the configuration file required to provide services to the request. Please check the specific error details below and modify the configuration file appropriately.
Parser Error message: Unrecognized configuration section appSettings.
This section does not find a definition in web.config and the machine.config it inherits.
And then change, the above deleted part added to the web.config corresponding position, and then refresh, show again normal. Be careful, because you remove the default configuration, so that other locally run programs will not be able to use it properly because they are still using the default configuration and do not have the <appsettings> definition added separately in web.config. Turn back the original machine.config.
Now we know that all elements except the <configSections> section defined in Web.config are defined from the config file, including the web.config and the machine.config it inherits.
OK, we've found the starting point. Pause for a few seconds, try to explain the definition below, and then continue to look down.
<section name= "Data" requirepermission= "false" type= " DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke "/>
Yes, it declares a section and tells the CLR that if it encounters a section called <data>, it will call "DotNetNuke.Framework.Providers.ProviderConfigurationHandler," DotNetNuke. The. NET FrameWork provides us with some simple configuration section processing class libraries, see System.Configuration namespaces.
<section> requirepermission properties can be found in MSDN
Http://msdn2.microsoft.com/zh-CN/library/system.configuration.sectioninformation.requirepermission.aspx
Of course, the following definitions are basically the same, and now we're just focusing on <data>, and first look at what's inside it, so we can figure out which parameters it will handle when we find the handler.
Code Snippet 3 Release.config
< data
defaultprovider = "Sqldataprovider" >
< providers >
< clear/>
< add
Name = "Sqldataprovider"
Type = "DotNetNuke.Data.SqlDataProvider, Dotnetnuke.sqldataprovider"
connectionStringName = "Sitesqlserver"
upgradeconnectionstring = ""
ProviderPath = "~/providers/dataproviders/sqldataprovider/"
Objectqualifier = ""
Databaseowner = "dbo"/>
</providers >
</Data >
and see how DotNetNuke.Framework.Providers.ProviderConfigurationHandler handles these configurations.
Code Snippets 4 Dotnetnuke.library/components/providers/providerconfigurationhandler.vb Friend Class Providerconfigurationh Andler
Implements IConfigurationSectionHandler
Public Overridable Overloads Function Create (ByVal Parent As Object, ByVal context as Object, ByVal N Ode as System.Xml.XmlNode) as Object Implements iconfigurationsectionhandler.create
Dim Objproviderconfiguration as New providerconfiguration
Objproviderconfiguration.loadvaluesfromconfigurationxml (node)
Return objproviderconfiguration
End Function
End Class
class implements the IConfigurationSectionHandler interface, and this interface has only one method
Object Create (
Object Parent,
Object Configcontext,
XmlNode section
)
A description of this method is shown in MSDN 2005
Ms-help://ms. Msdnqtr.v80.chs/ms. Msdn.v80/ms. Netdevfx.v20.chs/cpref4/html/m_system_configuration_iconfigurationsectionhandler_create_2_23718a01.htm
[Reference MSDN2005]
You can extend the standard set of asp.net configuration settings with your own XML configuration elements. To complete this operation, you must create your own configuration section handlers.
The handler must be an implementation System.Configuration.IConfigurationSectionHandler interface or System.Configuration.ConfigurationSection class. NET Framework classes.
[end of reference]
All right, keep looking at Providerconfigurationhandler's implementation.
Dim Objproviderconfiguration as New providerconfiguration
Objproviderconfiguration.loadvaluesfromconfigurationxml (node)
Return objproviderconfiguration
The code in the providerconfiguration is not posted, he contains a hashtable inside, and the configuration information is kept inside.
This will automatically get the configuration information when the program is initialized. So how does this configuration get? Through the GetSection method of System.Configuration.ConfigurationManager class. Note that this class does not exist in. NET 1.1, and the same effect is achieved by using System.Configuration.ConfigurationSettings.GetSection () in 1.1. However, this method is marked as expired in 2.0, which means that. NET does not guarantee backward compatibility.
For more information, see MSDN2005
Ms-help://ms.msdnqtr.v80.chs/ms.msdn.v80/ms.netdevfx.v20.chs/cpref4/html/t_system_configuration_configurationmanager.htm
Well, before we go on to learn about DNN's configuration, we'll rehearse what we learned about the east