我一直试图遵循这个答案,试图在授权期间解密加密的有效负载,然后将其模型映射到控制器。
在客户端,只有Payload将被加密,而在服务器端,我正在尝试解密。问题是整个Response.content无法解密,因为只需要解密有效负载。
在内容内部,我们在Result中接收到有效负载,当我试图更改时,它显示它是只读的,我看不到任何其他选项。在上面的图片中,结果尚未加密,我正在测试是否可以更改。
我用另一种方式完成了这项工作,将整个加密字符串传递给控制器,然后对其进行解密,并映射到控制器内部的模型,如下所示:
[Route("api/xxxxxx")]
[HttpPost]
public HttpResponseMessage PostTest(string encryptedValue)
{
//creating an instance of class
HttpResponseMessage response = new HttpResponseMessage();
try
{
string decryptJson = AES.DecryptString(encryptedValue);
Model list = JsonConvert.DeserializeObject<Model>(decryptJson);
//rest of the operation
}
//to catch exceptions if any
catch (Exception ex)
{
output.Success = false;
output.Message = Literals.GetErrorMessage(ex.Message);
}
//creating response
response = Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(output));
//returning response
return response;
}
这是按预期进行的,但我正在尝试是否可以在授权时进行,而不是对每个控制器单独进行。
如有任何建议,我们将不胜感激。