Read / modify response to MVC action with filters

I have an HttpPost action as shown below:

[HttpPost]
public string GetPerson()
{
    string output = GetPerson();
    return output;
}

      

I am returning xml as string. Is it possible to read this line into actionfilter OnResultExecuted or OnResultExecuting methods?

+3


source to share


1 answer


On each of these action filters, you can get a result (object ActionResult

).

For OnResultExecuted

you can get it from propertyResultExecutedContext.Result

I've added a sample below.



public class InterceptValueAttribute : ActionFilterAttribute
{


    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {

        var result = filterContext.Result as ContentResult;

        var data = result.Content;

      //use data as required

    }

}

      

You can use it for your actions as shown below.

[HttpPost]
[InterceptValue]
public string GetPerson()
{
    string output = GetPerson();
    return output;
}

      

+1


source







All Articles