当给定无效ID时,应返回什么HTTP状态代码?

当给定无效ID时,应返回什么HTTP状态代码?,http,asp.net-mvc-2,http-headers,http-error,Http,Asp.net Mvc 2,Http Headers,Http Error,删除不存在的对象的请求应返回什么状态代码 public ContentResult DeleteEntity(int id, FormCollection FormData) { Database db = new Database(); TargetEntity te = db.TargetEntities.SingleOrDefault(t => t.Id == id); if(te == null) { Reponse.StatusCo

删除不存在的对象的请求应返回什么状态代码

public ContentResult DeleteEntity(int id, FormCollection FormData)
{
    Database db = new Database();
    TargetEntity te = db.TargetEntities.SingleOrDefault(t => t.Id == id);
    if(te == null)
    {
        Reponse.StatusCode = 400; //Is this correct?
        return Content("Deletion failed. Invalid ID: " + id);
    }
    //Delete the entity
    return Content("Successfully Deleted");
}
请求本身没有问题,只是碰巧指定的ID无效(或者项目已被删除),所以我不确定400范围。我很确定这500个代码更不适合这种情况,因为服务器上没有出现任何问题(只是要求它删除一些不存在的东西)

什么状态代码在这里最合适

删除不存在的对象的请求应返回什么状态代码

public ContentResult DeleteEntity(int id, FormCollection FormData)
{
    Database db = new Database();
    TargetEntity te = db.TargetEntities.SingleOrDefault(t => t.Id == id);
    if(te == null)
    {
        Reponse.StatusCode = 400; //Is this correct?
        return Content("Deletion failed. Invalid ID: " + id);
    }
    //Delete the entity
    return Content("Successfully Deleted");
}

这很有道理。我最初对它不屑一顾,因为在我看来,它更倾向于请求一个不存在的位置(并且删除URL存在,只是不存在对象)。