首页 > 解决方案 > 在 asp.net 核心中间件中反序列化 HttpContext 上下文响应

问题描述

我想在我的异常中间件中反序列化 HttpContext 上下文响应,例如

context.Response.Deserialize<myclasss>();

如果它根据myclass成功反序列化,我想发送一个特定的响应对象,例如

 StatusCode = (int)HttpStatusCode.InternalServerError,
 Message = "something went wrong"

标签: asp.net.netasp.net-core.net-core

解决方案


在这种情况下,我使用

context.Response.ReadAsString().Deserilize<MyClass>()

使用 NewtonSoft.Josn 库进行反序列化


推荐阅读