【发布时间】:2021-07-27 17:00:03
【问题描述】:
我正在使用web api 到JSON 和custom CVS 解析器导出大量数据。一切正常,但我想在查询返回 0 条记录时返回 204 status code。我找不到设置状态码的方法,因为我返回IQueryable<Log>。有什么建议吗?
[HttpGet]
[Route("user/statistic")]
public IQueryable<Log> Statistic(int userId, DateTime startDate, DateTime endDate, CancellationToken cancellationToken)
{
var logs = _context.Find(userId, startDate, endDate);
return logs;
}
public IQueryable<Log> Find(int userId, DateTime startDate, DateTime endDate)
{
var startDateSql = startDate.AddDays(-1).Date;
var endDateTimeSql = endDate.AddDays(1).Date;
return Logs.Where(w => w.UserId == userId && w.DateStamp > startDateSql && w.DateStamp < endDateTimeSql).AsNoTracking();
}
【问题讨论】:
-
HttpContext.Response.StatusCode = 204;值得一试
标签: c# asp.net-web-api rest