我正在尝试向客户提出请求,如果客户不存在,则应返回某种"未找到"页面.以下哪项是用于此类任务的最佳实践,为什么?
public ActionResult Index(int id)
{
if (customerService.GetCustomerById(id) == null)
return View("NotFound");
return View();
}
Run Code Online (Sandbox Code Playgroud)
要么
public ActionResult Index(int id)
{
if (customerService.GetCustomerById(id) == null)
throw new HttpException(404, "Customer not found");
return View();
}
Run Code Online (Sandbox Code Playgroud)
扔了404.真的没有争论.这不是成为一名REST门徒,而是网络的运作方式.
您可以返回视图和 404.帮助用户或提供搜索框或指向某些畅销商品通常很有帮助,但是对客户明确NotFound并始终在HTTP响应中返回404.毫无疑问.
编辑:这是一个很好的指导:http://www.codinghorror.com/blog/2007/03/creating-user-friendly-404-pages.html
归档时间: |
|
查看次数: |
3779 次 |
最近记录: |