IIS Server和Spring.NET对象实例化失败

时间:2012-03-21 15:09:33

标签: c# asp.net iis web-config spring.net

我在我的Web应用程序中使用Spring.NET。最初,应用程序设置为使用Visual Studio Development Server。一切都很好。但当我更改它以使用本地IIS Web服务器并创建一个虚拟目录并运行我得到System.NullReferenceException的应用程序。我想我需要以这样的方式配置我的Web.config,以便Spring.NET与IIS一起工作。 Web.config文件是:

<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>

我还有什么要补充的。它之前工作正常,但现在它给了我错误。你将不胜感激。

1 个答案:

答案 0 :(得分:3)

您的web.config缺少所需配置的部分内容,来自文档:

  

Windows Server 2008,Win7和Windows上的IIS 7.0配置   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