C#C
C#2y ago
Sebastian

Receiving 400 on production, local env works fine

Hey,

I have same ASP.NET Core app running both on my localhost and on production (docker).
The only difference between the two are environment variables (aspnet env - release for prod and development for localhost).

When I run following powershell to call one of my endpoints:
$headers = @{
    'accept' = '*/*'
    'Content-Type' = 'application/json'
}
$body = @{
    'nonce' = '7ba0879e-476e-4962-85b9-9d36be449d21'
    'integrationType' = 'Slack'
}
Invoke-RestMethod -Uri 'https://localhost:8084/Integration' -Method 'POST' -Headers $headers -Body ($body | ConvertTo-Json)
Invoke-RestMethod -Uri 'https://{obfuscated}/Integration' -Method 'POST' -Headers $headers -Body ($body | ConvertTo-Json)

The localhost goes through and production throws:
Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ProblemDetails'.
Executed action {obfuscated}.IntegrationController.MatchIdentityAsync ({obfuscated}) in 26.5296ms
Executed endpoint '{obfuscated}.Controllers.IntegrationController.MatchIdentityAsync ({obfuscated})'
HTTP POST /Integration responded 400 in 37.0021 ms
Request finished HTTP/1.1 POST http://{obfuscated}/Integration - 400 null application/problem+json; charset=utf-8 37.7163ms


This is how my controller looks:
[ApiController]
[Route("[controller]")]
public class IntegrationController : ControllerBase
{
  // ...

  [HttpPost]
  // [Authorize]
  public async Task<IActionResult> MatchIdentityAsync([FromBody] IntegrationAuthDTO reqDTO)
  {
    _logger.LogInformation($"Matching identity, Nonce - {reqDTO.Nonce}, Integration - {reqDTO.IntegrationType}");
  }
}

// IntegrationAuthDTO
public class IntegrationAuthDTO
{
    public string Nonce { get; set; } = default!;
    public string IntegrationType { get; set; } = default!;
}


Any ideas why this is happening?
Was this page helpful?