Referencing Action Parameters from ExceptionLogger

☆樱花仙子☆ 提交于 2019-11-30 19:22:56

Ok it looks like I can get the body text from HttpContext by reading InputStream on the Request object like this:

string bodyText = string.Empty;

using (var sr = new StreamReader(HttpContext.Current.Request.InputStream))
{
    sr.BaseStream.Seek(0, SeekOrigin.Begin);
    bodyText = sr.ReadToEnd();
}

This code has been successful me so far for getting my posted json data.

Here's action parameters for future reference

public class HomeController : ApiController {
    public string Get(string id, [FromHeader] Whoever whoever) {

    public string Post(Whatever whatever) {


var args = ((ApiController) context.ExceptionContext
           .ControllerContext.Controller)).ActionContext.ActionArguments

if (args.ContainsKey("whatever")) {
   var whatever = (Whatever)args["whatever"];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!