I am writing custom filter in my Web API and there I want to modify the result of ActionExecutedContext inside the OnActionExecuted method.
I got the result type as OkObjectResult as the action method is returning IActionResult.
public void OnActionExecuted(ActionExecutedContext context)
{
var myResult = context.Result;
//Type of myResult is OkObjectResult
}
So here how can I convert this OkObjectResult to my model Object, So that I can use the properties and manipulate the values.
Appreciated any suggestion.
The OkObjectResult's "Value" property returns the Object. You can modify the Object's properties or even replace it with a new one. Hope this works for you. If it does, please mark this as answer.
Sample CODE: