當我嘗試調用刪除網頁API,我得到:無法調用刪除網頁API
NetworkError: 404 Not Found - /api/tradespendentryip/5
我的API控制器看起來是這樣的:
public class TradeSpendEntryIPController : ApiController
{
// DELETE api/tradespendentryip/5
public void Delete(int id)
{
string x = id.ToString(); //I put a breakpoint here which never gets hit
}
}
我把它這個jQuery的片段,硬編碼創建Web API時生成的提示URL:
$.ajax({
type: "DELETE",
url: "/api/tradespendentryip/5"
}).done(function(msg) {
alert('Record deleted.');
}).fail(function(jqXHR, textStatus){
alert('Unable to delete this record at this time.');
});
檢查Firebug中的網絡選項卡時,我總是得到「Net workError:404未找到 -/API/tradespendentryip/5"
從網絡上的一些研究,我試圖調節我的web.config,這樣的WebDAV不會干涉:
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
</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="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>
沒有任何人知道這些問題可能是什麼?我也有這表明在我的日誌生成此事件「路徑‘刪除’禁止」:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 02/04/2013 1:50:18 PM
Event time (UTC): 02/04/2013 4:50:18 PM
Event ID: 646d46d6edab4c049b10948279201c2f
Event sequence: 42
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: 972ee575-22-130093949467510162
Trust level: Full
Application Virtual Path:/
Application Path: C:\Sites\TPS\Development\Source\TPS\Source\TPS.Website\
Machine name: MACHINENAME
Process information:
Process ID: 6532
Process name: WebDev.WebServer40.exe
Account name: domain\chardie
Exception information:
Exception type: HttpException
Exception message: Path 'DELETE' is forbidden.
在System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext的背景下) 在System.Web.HttpApplication。 CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在System.Web.HttpApplication.ExecuteStep(IExecutionStep一步,布爾& completedSynchronously)
Request information:
Request URL: /Canada/TradeSpendingSales/api/tradespendentryip/5
Request path: /Canada/TradeSpendingSales/api/tradespendentryip/5
User host address: ::1
User: domain\chardie
Is authenticated: True
Authentication Type: NTLM
Thread account name: domain\chardie
Thread information:
Thread ID: 14
Thread account name: domain\chardie
Is impersonating: False
Stack trace: at System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
此路線是否已註冊?您可以使用此代碼檢查它'RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes)' – 2013-04-02 17:24:15
那麼,我不得不穀歌,但安裝後,確實表明,我打錯了路線。偉大的工具,真的有幫助,因爲我通常使用Glimpse來查看我的路線如何解決,但這不適用於Web API。這個小工具是一種享受,它值得問這個問題! –