Dotnet
Authentication and Authorization - Registration Part 1

Modify Model Validation Behavior

Mute
Current Time 0:00
/
Duration Time 0:00
Loaded: 0%
Progress: 0%
Stream TypeLIVE
Remaining Time -0:00
 
PRO

I finished! On to the next tutorial

Demo: Change Model Validation Error Response

In Conduilt.Api Project
  • Modify Startup.cs, ConfigureService method
  • Order in which the code is processed matters
  • Put the code after AddControllers()
            services.Configure<ApiBehaviorOptions>(options =>
            {
                    options.InvalidModelStateResponseFactory = context =>
                    {
                            var errors = new SerializableError(context.ModelState);
                            var result = new UnprocessableEntityObjectResult(new { errors });
                            return result;
                    };
            });

Conduit Github Repo

Tag Name: modify-model-validation-behavior