4
調用DELETE方法Web API未到達服務器。在網絡上搜索了類似的問題後,沒有爲我工作。 以下是我的解決方案中的代碼簡介。Web API刪除方法不起作用
的Web API:
[AuthorizeService]
[HttpDelete]
public HttpResponseMessage Delete(Int32 id)
{
String username = User.Identity.Name;
this._clientDataManager.DeleteRestaurant(id,username);
return new HttpResponseMessage(HttpStatusCode.OK);
}
AJAX調用:
$.ajax({
url: 'localhost:53378/api/RestaurantWebAPI/1135',
type: "DELETE",
statusCode: {
200: function (data) {
//success
}
}, beforeSend: setHeader
});
的Web.Config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<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>
</system.webServer>
得到任何幫助。
您可以刪除試用版的AuthorizeService屬性並查看它是否可訪問? – Adil
@ancdev你確定'AuthorizeService'方面或過濾器不能阻止你的操作調用嗎? –
我的問題是響應是404未找到。這個屬性在那裏執行一個簡單的認證。 – ancdev