ASP.NET&Spring.NET&NHibernate最佳实践(三)——第2章环境准备
2.1. 开发工具
Microsoft Visual Studio 2005
ASP.NET AJAX Extensions V1.0(http://www.asp.net/ajax/)
AJAX Control Toolkit V1.0.20229(http://www.codeplex.com/AtlasControlToolkit/)
Spring .NET V1.1.2 (http://www.springframework.net/)
NHibernate V1.2.1.GA(http://www.hibernate.org/343.html)
2.3.2. Web.config
2.3.3. 母版页(MasterPage.master)
(略)
2.4. Spring.NET配置
2.4.1. 数据库配置(Config/ Common.Config)
本示例采用Access数据库,DbProvider使用OleDb-2.0,NHibernate使用 JetDriver驱动,需要引用NHibernate.JetDriver.dll。
2.4.2. Web.Config
新增spring配置节
新增httpModule
spring节
完整代码下载:/Files/guushuuse/AA_SalaryPrj_2.zip
Microsoft Visual Studio 2005
ASP.NET AJAX Extensions V1.0(http://www.asp.net/ajax/)
AJAX Control Toolkit V1.0.20229(http://www.codeplex.com/AtlasControlToolkit/)
Spring .NET V1.1.2 (http://www.springframework.net/)
NHibernate V1.2.1.GA(http://www.hibernate.org/343.html)
2.2. 解决方案结构
2.3. ASP.NET配置
2.3.1. 网站地图
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="首页" description="">
<siteMapNode url="~/Salaries.aspx" title="工资管理" description="" />
<siteMapNode url="~/SalaryQuery.aspx" title="工资查询" description="" />
<siteMapNode url="~/Depts.aspx" title="部门管理" description="" />
<siteMapNode url="~/Employees.aspx" title="员工管理" description="" />
<siteMapNode url="~/Users.aspx" title="用户管理" description="" />
<siteMapNode url="~/Roles.aspx" title="角色管理" description="" />
<siteMapNode url="~/UserRole.aspx" title="权限设置" description="" />
</siteMapNode>
</siteMap>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="首页" description="">
<siteMapNode url="~/Salaries.aspx" title="工资管理" description="" />
<siteMapNode url="~/SalaryQuery.aspx" title="工资查询" description="" />
<siteMapNode url="~/Depts.aspx" title="部门管理" description="" />
<siteMapNode url="~/Employees.aspx" title="员工管理" description="" />
<siteMapNode url="~/Users.aspx" title="用户管理" description="" />
<siteMapNode url="~/Roles.aspx" title="角色管理" description="" />
<siteMapNode url="~/UserRole.aspx" title="权限设置" description="" />
</siteMapNode>
</siteMap>
2.3.2. Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<pages theme="Default">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions"/>
<add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
<add tagPrefix="gfc" namespace="GFC.Web.UI" assembly="GFC.Web.UI"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<authentication mode="Forms">
<forms loginUrl="~/SignIn.aspx" name=".SalaryPrj" protection="All" slidingExpiration="True" timeout="60">
</forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
<compilation>
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
</configuration>
<configuration>
<system.web>
<pages theme="Default">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions"/>
<add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
<add tagPrefix="gfc" namespace="GFC.Web.UI" assembly="GFC.Web.UI"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<authentication mode="Forms">
<forms loginUrl="~/SignIn.aspx" name=".SalaryPrj" protection="All" slidingExpiration="True" timeout="60">
</forms>
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
<compilation>
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
</configuration>
2.3.3. 母版页(MasterPage.master)
(略)
2.4. Spring.NET配置
2.4.1. 数据库配置(Config/ Common.Config)
本示例采用Access数据库,DbProvider使用OleDb-2.0,NHibernate使用 JetDriver驱动,需要引用NHibernate.JetDriver.dll。
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<db:provider id="DbProvider"
provider="OleDb-2.0"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Database.mdb"/>
<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Guushuuse.SalaryPrj.HR</value>
<value>Guushuuse.SalaryPrj.Salary</value>
<value>Guushuuse.SalaryPrj.Security</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<entry key="hibernate.dialect" value="NHibernate.JetDriver.JetDialect, NHibernate.JetDriver" />
<entry key="hibernate.connection.driver_class" value="NHibernate.JetDriver.JetDriver, NHibernate.JetDriver" />
</dictionary>
</property>
</object>
<object id="HibernateTransactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="SessionFactory"/>
</object>
<object id="hibernateTemplate" type="Spring.Data.NHibernate.HibernateTemplate">
<property name="SessionFactory" ref="sessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="CacheQueries" value="true" />
</object>
<object id="autoProxyCreator"
type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop">
</object>
<object id="transactionAdvisor"
type="Spring.Transaction.Interceptor.TransactionAttributeSourceAdvisor, Spring.Data">
<property name="TransactionInterceptor" ref="transactionInterceptor"/>
</object>
<object id="transactionInterceptor"
type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
<property name="TransactionManager" ref="HibernateTransactionManager"/>
<property name="TransactionAttributeSource" ref="attributeTransactionAttributeSource"/>
</object>
<object id="attributeTransactionAttributeSource"
type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data">
</object>
</objects>
xmlns:db="http://www.springframework.net/database">
<db:provider id="DbProvider"
provider="OleDb-2.0"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Database.mdb"/>
<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Guushuuse.SalaryPrj.HR</value>
<value>Guushuuse.SalaryPrj.Salary</value>
<value>Guushuuse.SalaryPrj.Security</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<entry key="hibernate.dialect" value="NHibernate.JetDriver.JetDialect, NHibernate.JetDriver" />
<entry key="hibernate.connection.driver_class" value="NHibernate.JetDriver.JetDriver, NHibernate.JetDriver" />
</dictionary>
</property>
</object>
<object id="HibernateTransactionManager"
type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="SessionFactory" ref="SessionFactory"/>
</object>
<object id="hibernateTemplate" type="Spring.Data.NHibernate.HibernateTemplate">
<property name="SessionFactory" ref="sessionFactory" />
<property name="TemplateFlushMode" value="Auto" />
<property name="CacheQueries" value="true" />
</object>
<object id="autoProxyCreator"
type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop">
</object>
<object id="transactionAdvisor"
type="Spring.Transaction.Interceptor.TransactionAttributeSourceAdvisor, Spring.Data">
<property name="TransactionInterceptor" ref="transactionInterceptor"/>
</object>
<object id="transactionInterceptor"
type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data">
<property name="TransactionManager" ref="HibernateTransactionManager"/>
<property name="TransactionAttributeSource" ref="attributeTransactionAttributeSource"/>
</object>
<object id="attributeTransactionAttributeSource"
type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data">
</object>
</objects>
2.4.2. Web.Config
新增spring配置节
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
</sectionGroup>
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
</sectionGroup>
新增httpModule
<add type="Spring.Context.Support.WebSupportModule, Spring.Web" name="WebSupportModule"/>
<add type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate12" name="OpenSessionInViewModule"/>
<add type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate12" name="OpenSessionInViewModule"/>
spring节
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
</parsers>
<context>
<resource uri="~/Config/Common.config"/>
<resource uri="~/Config/Guushuuse.SalaryPrj.HR.Config"/>
<resource uri="~/Config/Guushuuse.SalaryPrj.Salary.Config"/>
<resource uri="~/Config/Guushuuse.SalaryPrj.Security.Config"/>
</context>
</spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
</parsers>
<context>
<resource uri="~/Config/Common.config"/>
<resource uri="~/Config/Guushuuse.SalaryPrj.HR.Config"/>
<resource uri="~/Config/Guushuuse.SalaryPrj.Salary.Config"/>
<resource uri="~/Config/Guushuuse.SalaryPrj.Security.Config"/>
</context>
</spring>
完整代码下载:/Files/guushuuse/AA_SalaryPrj_2.zip
posted on 2008-05-10 14:30 guushuuse 阅读(4106) 评论(12) 编辑 收藏 举报