MVC4+Springnet+Nhibernate学习系列随笔(一)

Springnet与asp.net mvc4集成大体步骤

1.首先要在MVC项目中引用的两个程序集(Spring.Web与Spring.Web.Mvc4)

2.修改MVC项目的Global.asax文件,将  public class MvcApplication : System.Web.HttpApplication继承的System.Web.HttpApplication修改成继承   SpringMvcApplication类,此类包含于Spring.Web.Mvc4程序集中

3.修改webConfig文件如下

 

 

<?xml version="1.0" encoding="utf-8"?>
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问2
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!--SpringNet配置-->
    <sectionGroup name="spring">
     <section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc4"/>
    </sectionGroup>
 </configSections>
  <appSettings>
    <add key="AppDataBase" value="Data Source=.\YXDSQL2008;DataBase=MyProject;uid=sa;pwd=sasa;Integrated Security=False;User Instance=False;Connect timeout = 300" />
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <connectionStrings>
    <!--<add name="ConnectionString" connectionString="Data Source=.;DataBase=CheckMail;uid=sa;pwd=sasa;Integrated Security=False;User Instance=False;Connect timeout = 300" />-->
  </connectionStrings>
  
  <!--SpringNet配置-->
  <spring>
    <context>
      <resource uri="~/Config/Controllers.xml"/>
    </context>
 </spring>
  
  
  <system.web>
    <httpRuntime maxQueryStringLength="9999" />
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxQueryString="9999" />
      </requestFiltering>
    </security>
    <validation validateIntegratedModeConfiguration="false" />
    <!--注意这个小结必须配置,主要作用是实例化:Spring.Web.dll值得“Spring.Context.Support”
     空间下的WebSupportModule类,此类作用就是拦截客户端的请求进入SpringNet模块处理-->
    <modules runAllManagedModulesForAllRequests="true" >
      <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

 

  经过以上的大体的三步,就完成MVC4与SpringNET的简单的整合

posted @ 2014-08-24 11:57  沈阳晓东  阅读(768)  评论(0编辑  收藏  举报