从角度前端调用删除。错误显示:
Http failure response for http://devserver.us/MyApp/api/additive/3: 404 Not Found
角客户端中的删除方法:
onDelete(additive: Additive) {
if (confirm("Are you sure you want to delete this additive?")) {
var id = additive.AdditiveId;
this._additiveService.delete(id).subscribe(result => {
var ad = result;
console.log(id + " has been deleted.");
this.refresh();
}, error => console.log(error));
}
}
添加服务:
private url = this.baseUrl + "api/additive/";
delete(id: number): Observable<Additive> {
return this.http.delete<Additive>(this.url+id, { withCredentials: true }).catch(this.handleError);
}
Web Api控制器:
// DELETE api/<controller>/5
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
var deleteid = id;
return NoContent();
}
控制器继承自基础api控制器:
public class AdditiveController : BaseApiController
{
....
[Route("api/[controller]")]
public class BaseApiController : Controller
{
......
它在localhost中工作正常但在部署到开发服务器(IIS 10)之后,所有GET都可以工作,但是DELETE返回404 Not Found。控制器的URL是正确的。
web config允许所有动词:
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
我检查了stdout日志和事件查看器,但它们不包含任何数据。
我如何1.获取详细的错误消息或2.修复此问题?
答案 0 :(得分:1)
原来问题出现在服务器上的applicationHost配置文件中。必须明确允许DELETE,但事实并非如此。