[英]What is correct way to do message formatting and validation?
Situation情况
I have Action in my controller that accepts JObject in parameters.我的 controller 中有 Action,它在参数中接受 JObject。
public IActionResult Test(JObject request)
For development environment requests will be sent as simple json with data using "application/json" content type.对于开发环境,请求将作为简单的 json 发送,数据使用“application/json”内容类型。
But for production environment we will use JWE to protect our data.但是对于生产环境,我们将使用 JWE 来保护我们的数据。 So request will be JWE token and content type will be "application/jose".所以请求将是 JWE 令牌,内容类型将是“application/jose”。
I create my custom InputFormatter
so I can easily read this token, decrypt it and retrieve my JObject
to pass it to controllers action.我创建了我的自定义InputFormatter
,以便我可以轻松读取此令牌、解密它并检索我的JObject
以将其传递给控制器操作。 Everything till this moment was ok but I faced problem of sending error message if something wrong with token (eg couldn't decrypt because pass phrase is wrong or the token itself is corrupted).到目前为止一切正常,但如果令牌有问题(例如,由于密码错误或令牌本身已损坏而无法解密),我将面临发送错误消息的问题。 InputFormatterResult.Failure()
doesn't accept any parameters. InputFormatterResult.Failure()
不接受任何参数。
So I want to understand where should I do this.所以我想了解我应该在哪里执行此操作。
HttpRequest -> something -> Action of controller HttpRequest ->某事-> controller 的操作
It happens that InputFormatterContext
contains ModelState that I can populate with errors and it will go through all pipeline.碰巧InputFormatterContext
包含我可以用错误填充的 ModelState ,它将通过所有管道 go 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.