当前位置: 首页 > 工具软件 > BlogEngine > 使用案例 >

BlogEngine源码分析——配置文件(一)

广亮
2023-12-01
阅读源码一般从web.config和首页default.aspx开始,BlogEngine的配置文件比较复杂,信息量也多,所以我决定先看个大体,然后从页面一点点的拆解代码。
 
web.config
 
    configSections指定配置节和命名空间声明
 
    为首的就是这个节点。节点下方只有一个子节点就是sectionGroup,里面指定了BlogEngine,其子节点<section/>定义配置节处理程序与配置元素之间的关联。
 
    MSDN解释这是一种分组策略,避免命名冲突。而在BlogEngine中则是对应了数据存储和链接的方式。
 
    <sectionGroup/>节点中的“BlogEngine”组下面对应的blogProvider子节点,当调用BlogEngine/blogProvider时,将会调用type中的对应类去处理,这里就是BlogEngine.Core程序集下的BlogEngine.Core.Providers.BlogProviderSection。
 
    当我去看这个类的时候发现,这里面显示的定义了默认XML为处理方式。继续向下看就会发现:
1
2
3
4
5
6
7
8
< BlogEngine >
         < blogProvider defaultProvider = "XmlBlogProvider" >
             < providers >
                 < add name = "XmlBlogProvider" type = "BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core" />
                 < add name = "DbBlogProvider" type = "BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" connectionStringName = "BlogEngine" />
             </ providers >
         </ blogProvider >
     </ BlogEngine >
 
    这个节点是对应上面的组节点,这样每个节点下面就可以自由的分配,这里可以自己配置数据存储方式,默认是xml。
 
    既然是默认的xml,那就去顺着配置去找XmlBlogProvider类,但是,但是对应程序集下面是没有这个文件的,因为文件的名字叫做:BlogRoll.cs,里面的类名是XmlBlogProvider,真是有点玩人。
 
    XmlBlogProvider继承了BlogProvider,BlogProvider是一个abstract类,其他链接类都继承于此,方便扩展。
 
    对于DbBlogProvider的数据库链接方式,节点中有个connectionStringName属性,用来说明对应的数据库链接字符串的配置节点名称。在这里是这样的:    
1
< add name = "DbBlogProvider" type = "BlogEngine.Core.Providers.DbBlogProvider, BlogEngine.Core" connectionStringName = "BlogEngine" />
 
 
    里面指定里连接字符串的名字为:BlogEngine。下面就必须要有对应的节点:
1
2
3
4
< connectionStrings >
         < clear />
         < add name = "BlogEngine" connectionString = "Data Source=MySQLServer;User ID=user;Password=password;persist security info=False;initial catalog=BlogEngine;" providerName = "System.Data.SqlClient" />
     </ connectionStrings >
    
    终于搞清楚了它的数据配置方式。下面继续。
 
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
< appSettings >
         < add key = "BlogEngine.FileExtension" value = ".aspx" />
         <!-- You can e.g. use "~/blog/" if BlogEngine.NET is not located in the root of the application -->
         < add key = "BlogEngine.VirtualPath" value = "~/" />
         <!-- The regex used to identify mobile devices so a different theme can be shown -->
         < add key = "BlogEngine.MobileDevices" value = "(iemobile|iphone|ipod|android|nokia|sonyericsson|blackberry|samsung|sec\-|windows ce|motorola|mot\-|up.b|midp\-)" />
         <!-- The name of the role with administrator permissions -->
         < add key = "BlogEngine.AdminRole" value = "Administrators" />
         <!-- The name of the role for anonymous(non-authenticated) users. -->
         < add key = "BlogEngine.AnonymousRole" value = "Anonymous" />
         <!-- The name of the role for Editors -->
         < add key = "BlogEngine.EditorsRole" value = "Editors" />
         <!--This value is to provide an alternative location for storing data.-->
         < add key = "StorageLocation" value = "~/App_Data/" />
         <!--This value is the folder name under the StorageLocation that data for blog instances will be stored in.-->
         < add key = "BlogInstancesFolderName" value = "blogs" />
         <!--A comma separated list of script names to hard minify. It's case-sensitive. -->
         < add key = "BlogEngine.HardMinify" value = "blog.js,widget.js,WebResource.axd" />
     </ appSettings >
    这里定义了常用的配置,比如文件后缀等常用配置。并没有什么不可理解的东西。
 
    下面就是一个不认识的节点:
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< system.serviceModel >
     < services >
         < service behaviorConfiguration = "AuthenticationServiceBehaviors" name = "System.Web.ApplicationServices.AuthenticationService" >
             < endpoint binding = "basicHttpBinding" contract = "System.Web.ApplicationServices.AuthenticationService" />
         </ service >
     </ services >
     < serviceHostingEnvironment aspNetCompatibilityEnabled = "true" />
     < behaviors >
         < serviceBehaviors >
             < behavior name = "AuthenticationServiceBehaviors" >
                 < serviceMetadata httpGetEnabled = "true" />
             </ behavior >
         </ serviceBehaviors >
     </ behaviors >
</ system.serviceModel >
 
    通过google可以得知这是一个WCF(Windows Communication Foundation)的节点,以前并没有接触过WCF,如果想要具体了解每个节点的作用可以参考这篇博文: http://www.cnblogs.com/xfrog/archive/2010/05/15/1736028.html
    
    
1
2
3
4
5
6
7
< system.web.extensions >
         < scripting >
             < webServices >
                 < authenticationService enabled = "true" requireSSL = "false" />
             </ webServices >
         </ scripting >
     </ system.web.extensions >
 
    system.web.extensions节点是指定 ASP.NET 扩展配置节的根元素,并包含用于配置 ASP.NET 服务和控制其行为的元素。而其子节点只有一个<scripting/>。看起来很厉害的样子。
    
    <scripting/>节点:指定用于 ASP.NET 网页(支持 AJAX)和用于启用或禁用应用程序服务的配置设置。这里可以控制webservices和ajax的行为,是个很重要的节点。
 
    具体的信息可以参看MSDN,BlogEngine中的配置说明:启用webservices,不使用安全连接。
 
    <scripting/>节点下面还有个重要的节点就是<scriptResourceHandler/>里面配置了ajax的相关信息。
 
    先到这里,休息一下……

转载于:https://www.cnblogs.com/mnight/archive/2012/08/30/2663980.html

 类似资料: