简体   繁体   English

进行消息格式化和验证的正确方法是什么?

[英]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.

相关问题 格式化以下 JSON 的正确方法是什么? - What is correct way formatting the below JSON? 为 IFormFile 实施流利验证的正确方法是什么 - What is a correct way to implement Fluent Validation for IFormFile 做多对多实体关系插入的正确方法是什么? - What is the correct way to do many to many entity relation insert? 我的第一个c#声明......这样做的正确方法是什么? - my first c# statement…what is the correct way to do this? 2021 年进行外部提供商登录的正确方法是什么? - What is the correct way to do external provider logins in 2021? 我应该捕获多少个异常,正确的处理方法是什么? - How many exceptions should I catch and what is the correct way to do it? 使用可空引用类型处理 controller 请求 model 验证的正确方法是什么? - What is the correct way to handle controller request model validation with nullable reference types? 速度,正确的方法吗? - Velocity, correct way to do it? WPF:有没有办法进行内联格式化? - WPF: is there a way to do inline formatting? 在ASP .NET中设置和显示JavaScript警报消息的正确方法是什么? - What is the correct way to set up and display a JavaScript alert message in ASP .NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM