代码之家  ›  专栏  ›  技术社区  ›  w0051977

如何填充x-requestid?

  •  0
  • w0051977  · 技术社区  · 6 年前

     [HttpGet]
            public IActionResult Create([FromHeader(Name = "x-requestid")] string requestId)
            {
                return View();
            }
    
            [HttpPost]
            public IActionResult Create(Person person, [FromHeader(Name = "x-requestid")] string requestId)
            {
                if (ModelState.IsValid)
                {
                    string test = "got here";
                }
                return View();
            }
    

    requestId始终为空。requestId是如何填充的?

    What is the X-REQUEST-ID http header? . 另一个问题的答案是建议安装以下Nuget包:

    Microsoft.ApplicationInsights.ASPNetCore
    

    然而,这没有什么区别。

    2 回复  |  直到 6 年前
        1
  •  0
  •   sellotape    6 年前

    通常,“x-*”标题是 non-standard ones .

        2
  •  0
  •   Ivan R.    6 年前

    您被绑定到名为“x-requestid”的请求头,但它应该被称为“x-request-ID”。试试看:

    [HttpGet]
    public IActionResult Get([FromHeader(Name = "x-request-id")] string requestId)
    {
        return View();
    }