You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Server validation with a validator component upgrade #36051
Per Ondřej's suggestion in #35972 (for .NET 6 or later because Minimal APIs didn't arrive until .NET 6) ...
Idea: Replace use of MVC controller with Minimal API in the section "Server validation with a validator component" to showcase the unified validation experience
The API controller uses MVC-based validation which also uses DataAnnotations attribute to specify validation rules. However, it is configured differently and might have different behavior in some cases (e.g. validation is skipped with ValidateNever attribute in MVC but with SkipValidation attribute in the unified validation code)
Up for debate: Speaking of "server validation" and "client validation" might also be a bit confusing in the context of Blazor Server - maybe rephrase the section using terminology such as "data API", "backend", or "backend API"?
@oroztocil ... It's not going very well thus far for the unified experience. As you're well aware, the unified experience out of a Minimal API is to send back a 400 - Bad Request with ProblemDetails when model validation fails. A BWA using Microsoft.Identity.Web's CallApiForUserAsync throws 💥 on a 400 - Bad Request by design. When I trap the exception, I lose the ProblemDetails payload. I'll need to work with it a bit more to figure out an approach that will work ... unless you're already aware of this problem and know what to do.
This approach that AI discusses might work in this scenario ...
Custom Exceptions: For cleaner architecture, many developers create a custom exception that accepts the HttpResponseMessage as a parameter to store and expose the response body for further evaluation.
Naaaaah ... not looking good.
I'm going to take a break and come back. I'm hitting a 🧠🔥 at the moment. We might not be able to recommend using CallApiForUserAsync with the unified experience and a Minimal API. Thus far, it's really fighting me to do it that way.
Activity
github-actions commentedon Sep 4, 2025
🏖️🌞 Summertime!! Woot!! 🏐⛵
Stand-by! ... A green dinosaur 🦖 will be along shortly to assist.
guardrex commentedon Apr 23, 2026
guardrex commentedon May 7, 2026
Note that the unified validation experience wasn't rolled into the approach. I'm rolling it in on the PR.
guardrex commentedon May 7, 2026
@oroztocil ... It's not going very well thus far for the unified experience. As you're well aware, the unified experience out of a Minimal API is to send back a 400 - Bad Request with
ProblemDetailswhen model validation fails. A BWA usingMicrosoft.Identity.Web'sCallApiForUserAsyncthrows 💥 on a 400 - Bad Request by design. When I trap the exception, I lose theProblemDetailspayload. I'll need to work with it a bit more to figure out an approach that will work ... unless you're already aware of this problem and know what to do.guardrex commentedon May 7, 2026
This approach that AI discusses might work in this scenario ...
Naaaaah ... not looking good.
I'm going to take a break and come back. I'm hitting a 🧠🔥 at the moment. We might not be able to recommend using
CallApiForUserAsyncwith the unified experience and a Minimal API. Thus far, it's really fighting me to do it that way.