Since from version beta of ASP.NET Web API, I have used HttpActionContext.RequestContentKeyValueModel to get input parameters from body of POST request:
public override void OnActionExecuting(HttpActionContext actionContext)
{
var requestContentKeyValueModel = actionContext.RequestContentKeyValueModel;
//Do something in here
base.OnActionExecuting(actionContext);
}
but in the new release version RC, this property disappeared, is there any alternative for this?
You can use HttpContext.Current.Request.Form.
EDIT
You can always hide it behind interface:
public interface IKeyValueProvider
{
string GetValue(string key);
}
class RequestFormKeyValueProvider : IKeyValueProvider
{
public string GetValue(string key)
{
return HttpContext.Current.Request.Form[key];
}
}
Inject IKeyValueProvider in your controllers and mock in your tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With