C# 修改ActionFilterAttribute中的HTTP内容

C# 修改ActionFilterAttribute中的HTTP内容,c#,asp.net-web-api,actionfilterattribute,C#,Asp.net Web Api,Actionfilterattribute,我将控制器操作设置为: [HttpPost] [DecryptBodyFilterAttribute] public InitializeSessionResponse InitializeSession([FromBody] InitializeSessionRequest request) { ... } http主体是json,可以自动反序列化到我的请求对象中。现在,我希望http正文内容是一个加密字符串,我将在ActionFilterAttribute中对其进行解密。加密/解密不是

我将控制器操作设置为:

[HttpPost]
[DecryptBodyFilterAttribute]
public InitializeSessionResponse InitializeSession([FromBody] InitializeSessionRequest request)
{
  ...
}
http主体是json,可以自动反序列化到我的请求对象中。现在,我希望http正文内容是一个加密字符串,我将在
ActionFilterAttribute
中对其进行解密。加密/解密不是问题所在。我的问题是在控制器中执行操作之前,将主体的值重置为新值

我的ActionFilterAttribute如下所示:

 public sealed class DecryptBodyFilterAttribute : ActionFilterAttribute
 {
    public DecryptBodyFilterAttribute()
    {}

    public override Task OnActionExecutingAsync(HttpActionContext actionContext, System.Threading.CancellationToken cancellationToken)
    {
        string encryptedString = actionContext.Request.Content.ReadAsStringAsync().Result;
        //... decrypt do whatever and end up with the new content below...

        string newContent = "Something here would be the decrypted json of the initializeSessionRequest";
        //I need to do something like the below
        //actionContext.Request.Content = newContent;

        return base.OnActionExecutingAsync(actionContext, cancellationToken);
    }
 }

我的问题与转换响应时的解决方案类似。内容(在我的案例请求中)我得到一个空对象,因此它对我不起作用。

你找到问题的解决方案了吗?@User7291我想我没有找到,最后在每个控制器方法中都找到了:(