Как проверить отсутствие ответа?
Помогите разобраться, есть следующий код контроллера
[HttpGet]
public async Task<ContentResult> Auction([FromQuery] int[] ids, [FromQuery] string platfrom, AuctionModel auctionModel)
{
var partners = _AdCampaignMsSqlBl.GetRtbPartners(ids);
var result = await _rtbService.GetAuctionResult(partners.Values, auctionModel);
if (!string.IsNullOrWhiteSpace(result))
{
return new ContentResult
{
Content = result,
ContentType = "application/xml",
StatusCode = 200
};
}
else
return new ContentResult
{
Content = null,
ContentType = "application/xml",
StatusCode = 200
};
}
Необходимо добавить фильтр, в которым будет проверяться равен ли ContentResult значению null или нет.
Пробовал вот такой фильтр, но в HttpContext.Response не нашел нужного мне свойства
public class MetricFilterPlatfrom : ResultFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext context)
{
if(context.HttpContext.Response != null)
// Код при true
else
// Код при false
}
}
Ответы (1 шт):
Автор решения: aepot
→ Ссылка
Не знаю, правильно это или нет, но я бы пошел другим путем - просто задал бы нужный тип ответа.
[HttpGet]
public async Task<ActionResult> Auction([FromQuery] int[] ids, [FromQuery] string platfrom, AuctionModel auctionModel)
{
var partners = _AdCampaignMsSqlBl.GetRtbPartners(ids);
var result = await _rtbService.GetAuctionResult(partners.Values, auctionModel);
if (result?.Length > 0)
{
return new ContentResult
{
Content = result,
ContentType = "application/xml",
StatusCode = 200
};
}
else return new NoContentResult(); // 204 No Content
}