我有这个控制器:
namespace Cantrel.Application.CantrelSearchApi.Controllers
{
[Route("api/[controller]")]
[Authorize]
public class MonitorsController : Controller
{
private readonly IMonitoringApiService monitoringService;
private readonly IClientsApiService clientsService;
private readonly ILogger<MonitorsController> logger;
public MonitorsController(IMonitoringApiService monitoringService,
IClientsApiService clientsService,
ILogger<MonitorsController> logger)
{
this.monitoringService = monitoringService;
this.clientsService = clientsService;
this.logger = logger;
}
[HttpGet("{id}")]
public async Task<IActionResult> Get(string id)
{
if (string.IsNullOrEmpty(null))
{
return BadRequest("No id was provided. Please provide a valid monitor id or subject id.");
}
try
{
MonitorDto monitor;
if (Guid.TryParse(id, out Guid monitorId))
{
monitor = await GetByMonitorId(monitorId);
}
else
{
monitor = await GetBySubjectId(id);
}
if (monitor == null)
{
return NotFound();
}
return Json(monitor);
}
catch (Exception ex)
{
logger.LogError($"[{Request.Path.Value}]: {ex.ToString()}");
return new StatusCodeResult(500);
}
}
我用邮递员打以下电话:
GET: {{api}}/Monitors/ABCDEFGH-1234-4567-8901-ABCDEFGHIJKL
我收到了一个
400 Bad Request
消息出错
No id was provided. Please provide a valid monitor id or subject id
.
我不确定我是否明白这是怎么回事。字符串显然既不为空也不为空。
请告诉我是否有任何其他类别的代码,我应该提供帮助诊断。