ActionFilter の OnActionExecuted メソッドを介して、いくつかの API エンドポイントの戻り値を取得する必要がある Web API アプリケーションがあります。
カスタム属性を使用して、変更が必要なデータを持つエンドポイントを識別していますが、HttpActionExecutedContext 内から実際の結果オブジェクトを見つけることができないようです。
助けてくれてありがとう!
ActionFilter の OnActionExecuted メソッドを介して、いくつかの API エンドポイントの戻り値を取得する必要がある Web API アプリケーションがあります。
カスタム属性を使用して、変更が必要なデータを持つエンドポイントを識別していますが、HttpActionExecutedContext 内から実際の結果オブジェクトを見つけることができないようです。
助けてくれてありがとう!
プロパティを介して戻り値を取得できResponse.Content
ます。アクションがオブジェクトを返した場合は、そのオブジェクトをキャストしてObjectContent
、戻り値の実際のインスタンスを取得できます。
public class MyFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext context)
{
var objectContent = context.Response.Content as ObjectContent;
if (objectContent != null)
{
var type = objectContent.ObjectType; //type of the returned object
var value = objectContent.Value; //holding the returned value
}
}
}