2012-11-12 70 views
2

我開發了ASP.NET Web API應用程序,該應用程序在Visual Studio 2010下運行時運行良好。它運行並且工作得非常完美。但是,當我把它(XCOPY)部署到它崩潰和不運行的Web服務器:在IIS7上部署ASP.NET Web API時出錯

Object reference not set to an instance of an object. System.Web.HttpApplication.ExecuteStep. System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync

到目前爲止,我已經試過:重新註冊ASP.NET與IIS(ASPNET_REGIIS.EXE -i )適用於x32和x64版本的.NET 使用VS 2010構建部署包命令部署應用程序,然後將此包導出到IIS中。

有什麼想法?

P.S.其他ASP.NET 4.0應用程序(不是MVC/Web API)在同一臺服務器上工作得很好。

UPDATE:我的web.config的部分(不包括連接字符串和應用程序設置)

<system.web> 
<customErrors mode="Off"/> 
<compilation debug="true" targetFramework="4.0" /> 
<authentication mode="None" /> 
<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> 
<profile defaultProvider="DefaultProfileProvider"> 
    <providers> 
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> 
    </providers> 
</profile> 
<membership defaultProvider="DefaultMembershipProvider"> 
    <providers> 
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 
    </providers> 
</membership> 
<roleManager defaultProvider="DefaultRoleProvider"> 
    <providers> 
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> 
    </providers> 
</roleManager> 
<sessionState mode="InProc" customProvider="DefaultSessionProvider"> 
    <providers> 
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /> 
    </providers> 
</sessionState> </system.web> 



    <system.webServer> 
<validation validateIntegratedModeConfiguration="false" /> 
<modules runAllManagedModulesForAllRequests="true" /> 
<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="1.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> 
+0

許多問題都可能導致此問題。檢查你是否使用會話。如果是,請發佈您的配置文件。如果沒有,請嘗試發佈有關您的代碼的更多信息 –

+0

我正在使用會話。我現在會發布我的web.config的一部分。它只是由Visual Studio爲我生成的standd web.config。 –

回答

0

我相信90%,這裏的問題是有關您的自定義消息處理程序。我相信這是一個錯誤,但團隊堅持認爲這不是。不知道他們將如何處理它。這裏是演練:

如果您在任何消息處理程序中從頭開始創建響應,那麼顯然默認情況下它不會攜帶RequestMessage屬性。因此,它與着名的「對象引用未設置爲對象的實例」失敗。使用後立即出現錯誤。例如,打擊代碼,這臺HttpResponseMessageRequestMessage性能,解決了問題,但我認爲這應該由框架來完成:

public class TerminatingMessageHandler : DelegatingHandler { 

    protected override Task<HttpResponseMessage> SendAsync(
     HttpRequestMessage request, 
     CancellationToken cancellationToken) { 

     var response = new HttpResponseMessage(HttpStatusCode.OK); 
     response.RequestMessage = request; 
     return Task.FromResult(response).ContinueWith(task => { 

      var responseMsg = task.Result; 

      var httpContext = responseMsg.RequestMessage.Properties["MS_HttpContext"] as HttpContextWrapper; 
      if (httpContext != null) 
       httpContext.Response.Headers.Remove("Server"); 

      return responseMsg; 
     }); 
    } 
} 

下面是錯誤報告:http://aspnetwebstack.codeplex.com/workitem/408如果這裏的例子對於你來說,如果你想讓這個問題得到解決,你也可以投票並留下評論。