2012-03-21 75 views
0

我在我的web應用程序中使用Spring.NET。在開始時,應用程序被設置爲使用Visual Studio Development Server。一切工作正常。但是,當我將其更改爲使用本地IIS Web服務器並創建虛擬目錄並運行該應用程序時,我得到了System.NullReferenceException。我想我需要以這樣的方式配置我的Web.config,以便Spring.NET能夠使用IIS。 Web.config文件是:IIS服務器和Spring.NET對象實例化失敗

<configuration> 
<configSections> 
    <sectionGroup name="common"> 
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> 
    </sectionGroup> 
    <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="databaseSettings" type="System.Configuration.NameValueSectionHandler" /> 
</configSections> 
<common> 
    <logging> 
    <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> 
     <arg key="configType" value="FILE-WATCH" /> 
     <arg key="configFile" value="~/Config/Log4Net.xml" /> 
    </factoryAdapter> 
    </logging> 
</common> 
<spring> 
    <parsers /> 
    <context> 
    <resource uri="~/Data.xml" /> 
    <resource uri="~/Web.xml" /> 
    </context> 
</spring> 
<databaseSettings> 
    <add key="db.datasource" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf;Integrated Security=True;User Instance=True" /> 
</databaseSettings> 
<appSettings> 
    <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" value="NHibernateSessionFactory" /> 
    <add key="Telerik.Skin" value="Sunset"/>  
</appSettings> 
<connectionStrings> 
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> 
</connectionStrings> 
<system.web> 
    <compilation debug="true" targetFramework="4.0"> 
    <assemblies> 
     <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> 
     <add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </assemblies> 
    </compilation> 
    <authentication mode="Forms"> 
    <forms loginUrl="~/Pages/Login.aspx" timeout="2880" defaultUrl="~/Pages/Secured/Home.aspx" /> 
    </authentication> 
    <membership> 
    <providers> 
     <clear /> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 
    </providers> 
    </membership> 
    <profile> 
    <providers> 
     <clear /> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /> 
    </providers> 
    </profile> 
    <roleManager enabled="false"> 
    <providers> 
     <clear /> 
     <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> 
     <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> 
    </providers> 
    </roleManager> 
    <httpModules> 
    <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" /> 
    <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32" /> 
    </httpModules> 
    <httpHandlers> 
    <add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" /> 
    <add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" /> 
    <add verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web" /> 
    <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" /> 
    </httpHandlers> 
    <pages> 
    <controls> 
     <add tagPrefix="spring" namespace="Spring.Web.UI.Controls" assembly="Spring.Web" /> 
    </controls> 
    </pages> 
</system.web> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
    <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />   
    </handlers> 
</system.webServer> 
<location path="Secured"> 
    <system.webServer> 
    <directoryBrowse enabled="false" /> 
    </system.webServer> 
</location> 
</configuration> 

還有什麼我必須在這裏添加。它以前工作正常,但現在它給我錯誤。你幫助表示讚賞。

回答

3

web.config缺乏必要配置的部分,從文檔:

配置IIS 7.0的Windows Server 2008上,Win7的和Windows Vista的

有一些配置是特定於使用IIS7, 適當的代碼snippit放置在下面顯示的web.config中。

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false"/> 
    <modules> 
    <add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/> 
    </modules> 
    <handlers> 
    <add name="SpringPageHandler" verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/> 
    <add name="SpringWebServiceHandler" verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" /> 
    <add name="SpringContextMonitor" verb="*" path="ContextMonitor.ashx" type="Spring.Web.Support.ContextMonitor, Spring.Web"/> 
    </handlers> 
</system.webServer> 

http://www.springframework.net/doc-latest/reference/html/web.html#d4e7051