2013-03-13 34 views
47

我有一個ASP.NET Web API與本地主機上的 「IIS快車」 運行時正常工作:1783的ASP.NET Web API應用程序提供404 7

Settings in VS

但是,當我未交 「使用IIS快車」,然後按 「創建虛擬目錄」 ...

New settings

...我只是得到404錯誤: The 404 error

任何想法最新怎麼了?謝謝!

+0

當你正在設置文件路徑。 – 2013-03-13 15:52:24

+0

你有沒有在你的系統托盤檢查在IIS上運行應用程序快遞 – 2013-03-13 15:55:14

+0

@Shekhar據我瞭解,當點擊創建虛擬目錄時,VS爲我做了這個。即物理路徑似乎是正確的,虛擬Pah是MySite1。 「文件路徑」是別的嗎? – Cotten 2013-03-13 15:57:15

回答

34

雖然顯着的回答得到它的工作,你真正需要添加到webconfig是:

<handlers> 
     <!-- Your other remove tags--> 
     <remove name="UrlRoutingModule-4.0"/> 
     <!-- Your other add tags--> 
     <add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition=""/> 
    </handlers> 

請注意,這些都沒有特定的順序,但您希望在添加之前移除它們。

我們最終得到404的原因是因爲Url路由模塊只在IIS中爲網站的根目錄開始。通過將模塊添加到此應用程序的配置中,我們讓模塊在此應用程序的路徑(您的子目錄路徑)下運行,並且路由模塊啓動。

+4

該解決方案是更好,因爲有對runAllManagedModulesForAllRequests負面影響=「真」 http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html – Oliver 2014-09-26 12:55:07

+0

這應該是公認的答案 – 2015-03-13 07:41:21

+0

我覺得這打破了所有靜態文件。它不應該在模塊部分? http://stackoverflow.com/a/16475231/1280068 – stuartdotnet 2015-06-16 03:27:30

0

我正在使用Visual Studio 2012,下載並安裝Microsoft最近發佈的Update 2(截至2013年4月)。

Visual Studio 2012 Update 2

有在更新與此問題相關的一些bug修復。

10

您可能需要安裝修補程序KB980368

This article describes a update that enables certain Internet Information Services (IIS) 7.0 or IIS 7.5 handlers to handle requests whose URLs do not end with a period. Specifically, these handlers are mapped to "." request paths. Currently, a handler that is mapped to a "." request path handles only requests whose URLs end with a period. For example, the handler handles only requests whose URLs resemble the following URL:

http://www.example.com/ExampleSite/ExampleFile .

After you apply this update, handlers that are mapped to a "*." request path can handle requests whose URLs end with a period and requests whose URLs do not end with a period. For example, the handler can now handle requests that resemble the following URLs:

http://www.example.com/ExampleSite/ExampleFile

http://www.example.com/ExampleSite/ExampleFile .

After this patch is applied, ASP.NET 4 applications can handle requests for extensionless URLs. Therefore, managed HttpModules that run prior to handler execution will run. In some cases, the HttpModules can return errors for extensionless URLs. For example, an HttpModule that was written to expect only .aspx requests may now return errors when it tries to access the HttpContext.Session property.

+0

這絕對解決了我的問題! – rogcg 2014-02-27 21:00:07

+0

如果您的Windows 2008 Server使用IIS 7.0(不是R2),那麼這是此修補程序的下載鏈接:http://www.microsoft.com/en-us/download/details.aspx?id=11342 – 2015-03-06 16:50:02

2

有人說runAllManagedModulesForAllRequests =「true」會有性能問題和MVC路由問題。 他們建議使用如下:

http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html

http://bartwullems.blogspot.com/2012/06/optimize-performance-of-your-web.html

+3

請嵌入/寫你的答案,而不僅僅是鏈接 – 2014-02-16 17:56:55

+0

我有一個巨大的性能損失,當我用runAllManagedModulesForAllRequests =「真」在web表單+網頁API asp.net應用 – costa 2016-08-03 23:04:32

1

我有同樣的問題。很多R & D我發現了這個問題。

但只要你的配置是芬恩意味着aspnet 64位和IIS好然後 我看到的唯一問題是路徑「web api採取本地directiry路徑」,以便您需要狂熱它。通過這樣的.. 〜../../../ api/products/

非常感謝您發佈的問題。我在配置文件中放了很多abt iis和其他設置。

7

此問題也可能由於以下原因而發生

1.在Web中。配置

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
</system.webServer> 

2.確保下面在網絡API部署

•System.Net.Http

•System.Net.Http服務器上的bin文件夾中是可用的。格式化

•System.Web.Http.WebHost

•System.Web.Http

如果發佈是通過Visual Studio進行發佈的,則默認情況下,這些程序集將不會複製到bin文件夾中,因爲Web API包是通過開發計算機中的Nuget安裝的。不過,如果你想獲得這些文件可作爲Visual Studio中的一部分發布,那麼你需要CopyLocal設置爲True這些組件

+0

你剛剛救了我幾個小時的痛苦。 +1! – 2015-02-27 00:02:51

+0

這個答案的第2部分解決了這個問題http://stackoverflow.com/questions/30315563/webapiconfig-register-clears-routes-defined-by-routeconfig-registerroutes-apon-d 第1部分是壞:(正如所解釋的HTTP ://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html你應該只添加url路由模塊:) – Spaceman 2015-05-20 04:03:39

14

對於我來說,除了具有runAllManagedModulesForAllRequests="true"我也只好下面編輯"path" 屬性。以前我的路徑屬性是"*.",這意味着它只能在包含點 字符的url上執行。但是,我的應用程序的url不包含點。當我切換到"*"然後它的工作。 這是我現在有:

<system.webServer> 
     <validation validateIntegratedModeConfiguration="false" /> 
     <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WebDAVModule"/> 
     </modules> 

     <handlers> 
      <remove name="WebDAV" /> 
      <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="*" 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="*" 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="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
     </handlers> 
    </system.webServer> 
0

我一直在爭奪這個問題幾天嘗試各種事情的建議。我的開發機器工作正常,但我正在部署的新機器給我的404錯誤。

在IIS管理器中,我比較了兩臺機器上的處理程序映射,以瞭解很多處理程序丟失的情況。原來,ASP.Net 5沒有安裝在機器上。

0

對我來說,這個問題與其他答案稍有不同,因爲我只在OPTIONS上收到404,但我已經在我的集成無擴展URL處理程序選項中特別聲明瞭選項。很混亂。

  1. 正如其他人所指出的,runAllManagedModulesForAllRequests =「真」在 模塊節點是一個簡單的方法來掩蓋式解決大多數Web API 404名發佈 - 我喜歡@DavidAndroidDev的回答是侵入性要少得多。但在我的情況下還有一些額外的東西。
  2. 不幸的是,我有這個集IIS下請求篩選的網站:

OPTIONS Issue with Request Filtering

通過將以下安全節點在web.config中是必要的敲了這一點 - 全包括system.webserver上下文:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WebDAVModule" /> 
    </modules> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <remove name="OPTIONSVerbHandler" /> 
     <remove name="TRACEVerbHandler" /> 
     <remove name="WebDAV" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
    <security> 
     <requestFiltering> 
     <verbs> 
      <remove verb="OPTIONS" /> 
     </verbs> 
     </requestFiltering> 
    </security> 
    </system.webServer> 

雖然它不是這個問題完美的答案,它是「IIS OPTIONS 404」的第一個結果Ø谷歌,所以我希望這可以幫助別人。我今天花了一個小時。

0

對我而言,在運行使用IIS Express的應用程序時,我在我的網站上收到了404錯誤,但未使用IIS Express(使用本地IIS)。如果我關閉用於運行IIS Express的瀏覽器,那麼404將會消失。對我來說,我有我的IIS Express項目調用本地IIS服務,所以我轉換IIS Express項目使用本地IIS,然後一切工作。由於某種原因,您似乎無法同時運行非IIS Express和本地IIS網站。

相關問題