ASP.NET CORE 6异常限制软件和验证
在ASP.NET Core 6中,我有一个自定义中间件,可以处理返回特定结构的异常:
services.AddControllers(options => options.Filters.Add(typeof(CustomHttpResponseExceptionFilter)));
效果很好。但是,当一个参数失败时,类似于以下参数验证:
GetSomethingAsync([Required][MinLength(2)]string orderNumber)
customhttpresponseexceptionfilter
未调用。
在哪里可以拦截EG数据注释[必需]
的故障?
In ASP.NET Core 6, I have a custom middleware that handles exceptions returning a specific structure:
services.AddControllers(options => options.Filters.Add(typeof(CustomHttpResponseExceptionFilter)));
Works nicely. However, when an argument fails a param validation like:
GetSomethingAsync([Required][MinLength(2)]string orderNumber)
the CustomHttpResponseExceptionFilter
isn't called.
Where can I intercept a failure for e.g. data annotation [Required]
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,您需要自定义 ModelStateInvalidFilter 。
为此,您可以在程序中实现以下内容
。 -errors?view = aspnetcore-6.0#验证 - failure-error-response“ rel =“ nofollow noreferrer”> Microsoft的文档。
Hello you need to customize the behavior of ModelStateInvalidFilter.
To do so, you can achieve that doing the following in your Program.cs
You will find more information at Microsoft's documentation.