N2CMS的web.config配置

来源:互联网 发布:网络平台建设合同 编辑:程序博客网 时间:2024/05/09 20:00


N2CMS的web.config配置

The web.config you get with the various N2 downloads should point you in the right direction and just work out of the box - the main part to change is the database connection string. Below gives details on all the web.config settings N2 adds and needs.

The basics

N2 needs the N2 element described below, the connection string and IIS6/7 settings described below. You also need to configure the N2 section:

<sectionGroup name="n2" type="N2.Configuration.SectionGroup, N2">        <section name="host" type="N2.Configuration.HostSection, N2" requirePermission="false"/>        <section name="engine" type="N2.Configuration.EngineSection, N2" requirePermission="false"/>        <section name="database" type="N2.Configuration.DatabaseSection, N2" requirePermission="false"/>        <section name="edit" type="N2.Configuration.EditSection, N2" requirePermission="false"/></sectionGroup>

And add some expression builder settings:

<compilation debug="true">        <expressionBuilders>                <add expressionPrefix="CurrentItem" type="N2.Web.Compilation.CurrentItemExpressionBuilder, N2"/>                <add expressionPrefix="CurrentPage" type="N2.Web.Compilation.CurrentPageExpressionBuilder, N2"/>                <add expressionPrefix="Code" type="N2.Web.Compilation.CodeExpressionBuilder, N2"/>                <add expressionPrefix="StartPage" type="N2.Web.Compilation.StartPageExpressionBuilder, N2"/>                <add expressionPrefix="HasValue" type="N2.Web.Compilation.HasValueExpressionBuilder, N2"/>        </expressionBuilders></compilation>

You will need to configure all pages so they don't get postback validation and have N2 controls registered without needing to use the @Register syntax:

<pages validateRequest="false" enableEventValidation="false">        <controls>                <add tagPrefix="n2" assembly="N2" namespace="N2.Web.UI.WebControls"/>                <add tagPrefix="n2" namespace="N2.Templates.Web.UI.WebControls" assembly="N2.Templates"/>        </controls></pages>

And also some sitemap support:

<siteMap defaultProvider="PublicSiteMap">        <providers>                <add name="PublicSiteMap" type="N2.Web.PublicSiteMapProvider, N2" startPageIsRoot="true"/>        </providers></siteMap>

Once these are present, you will then need to add/configure the IIS6/IIS7 elements, the N2 element, the connection string and authentication.

II6 settings

If you are running on IIS6, you will need the following section inside your system.web element:

<httpModules>        <add name="n2.initializer" type="N2.Web.InitializerModule,N2"/></httpModules><httpHandlers>        <add path="*.n2.ashx" verb="*" type="N2.Web.AjaxRequestHandler, N2"/></httpHandlers>

IIS7 settings

Under IIS7 the above can be skipped, and the following should be added under the system.webServer element:

<modules runAllManagedModulesForAllRequests="true">        <add name="n2.initializer" type="N2.Web.InitializerModule, N2"/></modules><handlers>        <add name="n2.ajax" path="*.n2.ashx" verb="*" type="N2.Web.AjaxRequestHandler, N2"/></handlers>

N2 Settings

The N2 element holds most of the configuration information N2 needs to run. You will need to define it first in your configSection element, as mentioned above (and repeated here again):

<sectionGroup name="n2" type="N2.Configuration.SectionGroup, N2">        <section name="host" type="N2.Configuration.HostSection, N2" requirePermission="false"/>        <section name="engine" type="N2.Configuration.EngineSection, N2" requirePermission="false"/>        <section name="database" type="N2.Configuration.DatabaseSection, N2" requirePermission="false"/>        <section name="edit" type="N2.Configuration.EditSection, N2" requirePermission="false"/></sectionGroup>
<n2>        <!-- If you install a database from scrach you'll need to insert some required pages.        This can be done by the web based installer located at http://yoursite/install/edit -->        <host rootID="1" startPageID="1">                <web extension=".aspx" isWeb="true"                         rewrite="RewriteRequest" observedExtensions=""                         observeEmptyExtension="false"                         ignoreExistingFiles="false">                                                <urls enableCaching="true"/>                </web>        </host>        <engine/>        <!-- Other flavours: SqlServer2005, SqlServer2000, MySql, SqLite -->        <database connectionStringName="N2CMS" flavour="MySql"/>        <edit>                <installer checkInstallationStatus="false"/>        </edit></n2>

Connection strings

The web.config in the binary release contains a few examples of connection strings to common databases. If you already have a connection string whose name you don't want to change you will have to change "connection string name property" in the castle configuration section (nhSettings below). Dont forget to create a database and configure the connection string.

<connectionStrings>                <!-- Some connection string examples                SQLite:                         <add name="N2CMS" connectionString="Data Source=|DataDirectory|\n2.db;Version=3;New=True;" providerName="System.Data.SQLite"/>                SQL Server 2005:        <add name="N2CMS" connectionString="Server=(local);Database=N2_Templates;Integrated Security=SSPI"/>                SQL Express 2005:       <add name="N2CMS" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\N2.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>                SQL Server 2000:        <add name="N2CMS" connectionString="Data Source=SQLServer2000;Database=SQLDatabase2000;User Id=SqlUser2000;Password=SqlPassword2000;Network Library=DBMSSOCN;" providerName="System.Data.SqlClient"/>                MySQL:                          <add name="N2CMS" connectionString="Data Source=MySQLServer;Database=MySQLDatabase;User Id=MySQLUser;Password=MySQLPassword;" providerName="MySql.Data.MySqlClient"/>                -->                <!-- Please not that you need to configure another database and remove \bin\system.data.sqlite.dll if you run in medium trust -->                <add name="N2CMS" connectionString="Data Source=|DataDirectory|\n2.sqlite.db;Version=3;New=True;" providerName="System.Data.SQLite" />                <!--<add name="N2CMS" connectionString="Data Source=.\SQLEXPRESS;Database=N2;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>--></connectionStrings>

Authentication

The super-user/root/admin password is configured in the authentication element in System.Web:

<system.web>        <authentication mode="Forms">                <forms loginUrl="edit/login.aspx" protection="All" timeout="30000" path="/">                        <credentials passwordFormat="Clear">                                <!-- WARNING: Change this default password -->                                <user name="admin" password="docs"/>                        </credentials>                </forms>        </authentication></system.web>

Users (N2 uses the ASP.NET 2.0 Membership provider system for its users) are configured in the Membership element in System.Web:

<system.web>        <!-- These membership and role providers store their data as content items.         You can also use the forms authentication credentials only (remove these sections)         or the default ASP.NET providers (check your ASP.NET documentation) -->        <membership defaultProvider="ContentMembershipProvider">                <providers>                        <clear/>                        <add name="ContentMembershipProvider" type="N2.Security.ContentMembershipProvider, N2.Security"/>                </providers>        </membership>        <roleManager enabled="true" defaultProvider="ContentRoleProvider">                <providers>                        <clear/>                        <add name="ContentRoleProvider" type="N2.Security.ContentRoleProvider, N2.Security"/>                </providers>        </roleManager></system.web>

来源:http://code.google.com/p/n2cms/wiki/WebConfig