asp.net - 在 asp.net 核心中间件中反序列化 HttpContext 上下文响应
问题描述
我想在我的异常中间件中反序列化 HttpContext 上下文响应,例如
context.Response.Deserialize<myclasss>();
如果它根据myclass成功反序列化,我想发送一个特定的响应对象,例如
StatusCode = (int)HttpStatusCode.InternalServerError,
Message = "something went wrong"
解决方案
在这种情况下,我使用
context.Response.ReadAsString().Deserilize<MyClass>()
使用 NewtonSoft.Josn 库进行反序列化
推荐阅读
- performance - 谷歌 V8 执行 WebAssembly 的性能不一致
- excel - 将数组中的分隔字符串值分隔为布尔变量
- ios - 如何将文本文件捆绑到 xcode 应用程序中以便在运行时读取?
- flask - config.py 中忽略了 Flask 环境
- python - 如何使用第二个数据帧的列名和第一个数据帧的两列中的值匹配两个数据帧
- sql - 使用 Databricks 中的原始 SQL 直接查询存储在 Azure Data Lake 中的 avro 数据文件
- python - 如何使用 BeautifulSoup 获取列表中文章的链接
- javascript - ReactJS 使用 setState() 处理对象数组
- django - 根据记录的用户权限创建带有字段的视图
- c++ - 如何使用共享库中的地址检测 4K 别名?