Good day. I try using the ActionFilterAttribute class to get the input parameters of a POST request in this way:

public override void OnActionExecuting(ActionExecutingContext filterContext) { log.Trace($"Params: {filterContext.HttpContext.Request.QueryString}"); } 

The request itself:

 function GetData() { $.ajax({ url: "http://localhost....", type: 'POST', dataType: 'json', data: JSON.stringify({ value: JSON.stringify("Параметры")}), crossDomain: true, processData: false, contentType: 'application/json, charset=utf-8', headers: { User: "User", Password: "Password" }, success: function (q, w, e) { alert(JSON.stringify(q)); }, error: function (q, w, e) { alert("Ошибка: " + w); } }); } 

The string filterContext.HttpContext.Request.QueryString comes all the time empty. Tried to get input parameters through filterContext.HttpContext.Request.InputStream; filterContext.HttpContext.Request.BinaryRead(int); filterContext.HttpContext.Request.InputStream; filterContext.HttpContext.Request.BinaryRead(int); , but they are also empty, although the request fulfills and returns the result. Maybe someone uses filters in MVC and can tell how to get the input parameters of the request in the OnActionExecuting method via the filterContext variable?

  • try so, value parameter var param = filterContext.ActionParameters["value"]; - Ruslan_K
  • @Ruslan_K, thank you very much), it works. You can issue as an answer, I will vote. - Jiraiya

1 answer 1

Here is what helped me:

  private Dictionary<string, object> parameters; public override void OnActionExecuting(ActionExecutingContext filterContext) { parameters = (Dictionary<string, object>)filterContext.ActionParameters; int count = 0; foreach (KeyValuePair<string, object> keyValue in parameters) { log.Trace($"Param {count}: (Key: {keyValue.Key}, Value: {keyValue.Value.ToString()})"); count++; } } 

Thanks Ruslan_K for the advice.