[HttpGet]
public List<UserInfo> GetList()
{
try
{
List<UserInfo> list = new List<UserInfo>();
list.Add(new UserInfo() { UserName = "jay1" });
list[10].id = 1000;
return list;
}
catch (Exception ex)
{
//在webapi中要想抛出异常必须这样抛出,否则只抛出一个默认500的异常
var response = new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent("{\"result\":\"" + ex.ToString() + "\"}"),
ReasonPhrase = "error"
};
throw new HttpResponseException(response);
}
}

相关文章:

  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
猜你喜欢
  • 2021-09-22
  • 2022-12-23
  • 2021-10-12
  • 2021-10-29
相关资源
相似解决方案