Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the HttpActionExecutedContext Result values

I have created a filter which inherits the System.Web.Http.Filters.ActionFilterAttribute in the asp.net web api and would like to access some of the data inside the HttpActionExecutedContext result object.

At what stage/when does this object get populated? As I looked at it when overriding the OnActionExecuted method and its always null?

Any ideas?

Edit:

for example here in my custom filter:

public override OnActionExecuted(HttpActionExecutedContext context)
{
    //context.Result.Content is always null

    base.OnActionExecuted(context);
}
like image 485
gdp Avatar asked Apr 23 '12 21:04

gdp


1 Answers

Use this function to get body of request in web api

private string GetBodyFromRequest(HttpActionExecutedContext context)
{
    string data;
    using (var stream = context.Request.Content.ReadAsStreamAsync().Result)
    {
        if (stream.CanSeek)
        {
            stream.Position = 0;
        }
        data = context.Request.Content.ReadAsStringAsync().Result;
    }
    return data;
}
like image 51
virender Avatar answered Oct 19 '22 22:10

virender