我需要WebAPI項目在不同的基礎路徑下工作,而不是平常。我在Visual Studio下創建了一個使用WebAPI和ASP.NET 5的簡單項目。在IISExpress中設置基路徑和ASP.NET中的webapi 5
將基路徑設置爲http://localhost:38170/我的項目工作正常,我可以從測試控制器(http://localhost:38170/api/values)獲取值。 在這個階段,我的IIS Express配置爲:
<site name="WebApi" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:38170:localhost" />
</bindings>
</site>
我試圖在項目屬性改變應用程序的網址,以反映我的需要: http://localhost:38170/xxx
現在正在運行的項目,打http://localhost:38170/xxx/api/values結果404試圖http://localhost:38170/api/values返回值從控制器,就好像沒有任何改變。我注意到,Visual Studio中的更改沒有以任何方式反映在IIS Express配置中(我不知道它們是否應該是......)。
我試圖改變路徑上IISExpress手動喜歡在這個線程:Creating virtual directories in IIS express。
<site name="WebApi" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/xxx" physicalPath="C:\WebApi\src\WebApi\wwwroot" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:38170:localhost" />
</bindings>
</site>
的結果是:
http://localhost:38170/api/values - 500.19錯誤(配置錯誤),這是非常好的 - 我不打算在此工作
http://localhost:38170/xxx/api/values - 在擊中httpPlatformHandler網關錯誤 - 502.3
我想這錯誤是在httpPlatformHandler配置的地方,但我不知道如何做到這一點與IIS快遞一起選擇。我的web.config是:
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
</system.webServer>
</configuration>
我試着像路徑屬性xxx/*
變化隨機變化,但沒有任何工程。
編輯: 要澄清的問題。
如何使用httpPlatformHandler和茶隼設置根以外的鹼路徑上IISExpress設置上ASP.NET 5(ASP.NET核心)的WebAPI。
只需檢查 - 嘗試退出/關閉/重新啓動IISExpress(從工具欄中的圖標)。有關於IIS的問題的報告,[像這個我_randomly_命中](http://stackoverflow.com/q/34028341/304683)。不說它的相關(我不知道)所以只是一個完整的檢查(至於爲什麼VS屬性的變化似乎並沒有設置) – EdSF
@ EDSF不幸檢查了一百次和一百次 - 結果如所述 – pg0xC