2011-05-19 63 views
0

我創建了一個在本地主機上正常工作的MVC應用程序。我使用visual studio將項目發佈到本地文件夾並將其上載到FTP位置。但在服務器上它不工作。如何在IIS 7.0中託管MVC應用程序?

我跟着一對夫婦的教程,但沒有結果 http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

有一些好的教程還是會有人幫助嗎? 謝謝

+6

什麼不起作用?怎麼了?你有什麼錯誤嗎? – 2011-05-19 21:07:30

+1

「這不起作用」 - 請說明它的失敗方式。你使用數據庫嗎?您可能需要在數據庫文件上設置適當的權限。但是還有很多其他的原因可能會導致失敗。 – fretje 2011-05-19 21:10:18

+0

它插入了嗎? – Gabe 2011-05-19 21:28:34

回答

2

我們遇到了運行問題。通常(但並非總是),通過Web Platform Installer在服務器上安裝ASP.NET MVC似乎可以解決任何問題。因人而異。

+0

是的,我很確定這是問題。 MVC庫和路由的東西沒有內置到IIS中。 – Tridus 2011-05-19 21:15:53

+3

@Tridus,實際上IIS 7支持mvc路由,它不是IIS 6。 – Gabe 2011-05-19 21:22:41

+0

@加貝 - 哦?嘿,我今天學到了東西。 :) – Tridus 2011-05-19 21:25:32

7

有一對夫婦的事情,你可以檢查:

  1. 檢查其下的應用程序池的應用程序運行,並檢查應用程序池使用的integrated pipeline代替classic
  2. 檢查web.config文件是否包含<system.webServer>元素。如果您使用集成管道,這是HttpModules註冊的地方。
  3. 檢查<modules>元素的屬性runAllManagedModulesForAllRequests設置爲"true"。這會導致HttpModules適用於所有請求,允許UrlRouteModule執行此操作。您還必須刪除並添加HttpModules。

基本上,web.config<system.webServer>部分應包含這樣的事情:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="ScriptModule"/> 
     <remove name="UrlRoutingModule"/> 
     <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
    </modules> 
    <handlers> 
     <remove name="WebServiceHandlerFactory-Integrated"/> 
     <remove name="ScriptHandlerFactory"/> 
     <remove name="ScriptHandlerFactoryAppServices"/> 
     <remove name="ScriptResource"/> 
     <remove name="MvcHttpHandler"/> 
     <remove name="UrlRoutingHandler"/> 
     <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 
    </handlers> 
</system.webServer> 

(注意,在1.0的MVC平臺的這種情況下版本用於你不應該複製&粘貼此片段。 。這純粹是它看起來應該是什麼樣子的跡象)

+1

+1 - 這幫助我解決了'modules'元素中缺少runAllManagedModulesForAllRequests =「true」'的問題。 – GiddyUpHorsey 2012-04-30 22:01:48

相關問題