0
votes

I am following this guide

https://docs.microsoft.com/en-us/azure/active-directory-b2c/rest-api-claims-exchange-dotnet

However the code has been deprecated - IHttpActionResult no longer exists in latest version of Net Core

That means this response type now highlights as an error

if (inputClaims.firstName.ToLower() == "test")
        {
            return Content(HttpStatusCode.Conflict, new B2CResponseContent("Test name is not valid, please provide a valid name", HttpStatusCode.Conflict));
        }

I believed that the method should become an ActionResult and return like this instead

if (inputClaims.firstName.ToLower() == "test")
        {
            return Ok(new B2CResponseContent("Test name is not valid, please provide a valid name", HttpStatusCode.Conflict));
        }

However, it appears if I do this, the policy simply ignores the error and carries on registering the user.

1

1 Answers

1
votes

You still have to return HTTP Status Code 409 (conflict). return Ok(..) will always return status code 200.

The correct way to return the response is:

if (inputClaims.firstName.ToLower() == "test")
{
       return Conflict(new B2CResponseContent("Test name is not valid, please provide a valid name", HttpStatusCode.Conflict));
}

or

if (inputClaims.firstName.ToLower() == "test")
{
       return StatusCode((int)System.Net.HttpStatusCode.Conflict, new B2CResponseContent("Test name is not valid, please provide a valid name", HttpStatusCode.Conflict));
}