MVC4+Springnet+Nhibernate學習系列隨筆(一)

Springnet與asp.net mvc4集成大致步驟web

1.首先要在MVC項目中引用的兩個程序集(Spring.Web與Spring.Web.Mvc4)spring

api

2.修改MVC項目的Global.asax文件,將  public class MvcApplication : System.Web.HttpApplication繼承的System.Web.HttpApplication修改爲繼承   SpringMvcApplication類,此類包含於Spring.Web.Mvc4程序集中mvc

3.修改webConfig文件以下app

 

 

<?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的簡單的整合

asp.net

相關文章
相關標籤/搜索