我有一個ASP.NET MVC應用程序。 我有單一的函數模式,這將被稱爲與HTTP POST和HTTP DELETE。ASP.NET MVC HTTP Post/Delete
雖然調用Post,但絕不會調用Delete。我確認IIS接受HTTP刪除。任何意見?
路線和控制器:
routes.MapHttpRoute(
name: "RegisterCard",
routeTemplate: "{version}/cards/{cardID}",
defaults: new { Controller = "MyController", Action = "
routes.MapHttpRoute(
name: "UnregisterCard",
routeTemplate: "{version}/cards/{cardID}",
defaults: new { Controller = "MyController", Action = "Delete" });
[HttpPost]
public async Task<HttpResponseMessage> Post(string version, string cardID);
{
}
[HttpDelete]
public async Task<HttpResponseMessage> Delete(string version, string cardID);
{
}
您正在使用哪個瀏覽器? IE 8和9不會很好地執行AJAX DELETE/PUT。嘗試在請求中添加「X-HTTP-Method-Override:Delete」標題並使用POST。這會觸發行動嗎? – SimonGoldstone
檢查這個答案,並通過您的配置文件 http://stackoverflow.com/questions/10906411/asp-net-web-api-put-delete-verbs-not-allowed-iis-8 –