During this period, I was studying Microsoft's. net petshop ,. net 2.0 and petshop4.0 are both released.) There are many articles about its architecture on the Internet, so it is not difficult to understand it. However, I found that I am more concerned with its technical implementation details. This should be related to my foundation: (, But I have recorded my learning details, I hope that, while consolidating my knowledge, I can provide some reference for you.
Start with web. config. Let's first analyze its web. config configuration file.
1. appsetting configuration section: This section mainly describes the database connection string information and data layer information.
2. httpruntime configuration section: the main function here is to dynamically load the assembly in the subconfiguration section at runtime.
<Runtime>
<AssemblyBinding xmlns = "urn: schemas-microsoft-com: asm. v1">
<QualifyAssembly partialName = "PetShop. SQLServerDAL" fullName = "PetShop. SQLServerDAL, version = 3.2.1.0, publicKeyToken = a7987b61c51ca872, culture = neutral"/>
</AssemblyBinding>
<AssemblyBinding xmlns = "urn: schemas-microsoft-com: asm. v1">
<QualifyAssembly partialName = "PetShop. shortledal" fullName = "PetShop. shortledal, version = 3.2.1.0, publicKeyToken = a7987b61c51ca872, culture = neutral"/>
</AssemblyBinding>
</Runtime>
In the qualifyAssembly node, fullname is used to specify to load the specified Assembly from the Global Assembly Cache. Therefore, PetShop. SQLServerDAL must be a global assembly.
3. I will not talk about it later. It is mainly used to implement forms authentication control. For details, refer to my use of HttpModule and forms authentication to Implement role authentication control.
Of course the article will not end here. It is impossible to understand the config configuration of petshop. The following describes how to write a config file.
1. Naming rules for each Tag Name:
The tag name and attribute name are in the Camel case format. This means that the first character of the tag name is in lower case, and the first letter of any followed word is in upper case. The attribute value is in the Pascal case format, which means that the first character is in uppercase, and the first letter of any followed word is in uppercase. Except true and false, they are always in lower case (from msdn, haha ).
2. Custom configuration section:
. The config file in. net inherits from the machine by default. config, you can refer to, the file is saved in the path c: \ windows \ microsoft.net \. under framework \ v1. ***** \ config. In addition to the nodes in machine. config, you can also customize your own nodes as follows:
<ConfigSections>
<SectionGroup name = "test">
<Section name = "setting" type = "System. Configuration. NameValueFileSectionHandler, System, Version = 1.0.5000.0, Culture = neutral, PublicKeyToken = b77a5c561934e089"/>
</SectionGroup>
</ConfigSections>
According to the above structure, add the following nodes:
<Test>
<Settings>
<Add key = "id" value = "000256"/>
</Settings>
</Test>
To read the value of the Configuration section in the program, you can use System. Configuration. ConfigurationSettings. GetConfig to obtain the value, as shown below:
NameValueCollection nvc = (NameValueCollection) (System. Configuration. ConfigurationSettings. GetConfig ("test \ settings "));
String aa = nvc ["id"]. ToString ();
3. type in the custom configuration section:
In the settings configuration section, I used the System-defined System. configuration. nameValueFileSectionHandler can also customize the type based on your own needs. You only need to inherit IConfigurationSectionHandler from the class you write and implement its creat method.
The Research of web. config has come to an end here. Please wait for the next article, global assembly and private assembly.