问题描述
ASP.NET Core 3.1 正在采用 POSTed JSON(用于在我刚刚起步的 Web API 中通过 SCIM v2 创建用户)并将其模型绑定到我的 C# 请求数据类 createuserRequest
就像冠军一样。如果 JSON 中有错误,它会产生很好的基于问题详细信息的错误。
例如如果缺少用户的姓氏(又名姓氏)(不应该是因为我[Require]
该属性),则响应 JSON 是:-
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1","title": "One or more validation errors occurred.","status": 400,"traceId": "|dbd3da85-4991c45298582047.","errors": {
"Name.LastName": [
"The LastName field is required.","The field LastName must be a string with a minimum length of 1 and a maximum length of 100."
]
}
}
这是 ValidationProblemDetails
的结果,它适用于大多数用途,但不幸的是,它不适用于需要不同 JSON 格式 described here 的 SCIM。
例如SCIM 错误如下所示:-
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],"scimType":"mutability"
"detail":"Attribute 'id' is readOnly","status": "400"
}
如何在 ASP.NET Core 3.1 Web API 中用其他东西(在本例中是 SCIM 兼容的东西)替换 ProblemDetails
和 ValidationProblemDetails
?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)