Getting a Request.Headers value

后端 未结 7 1031
忘了有多久
忘了有多久 2020-12-01 07:33

Very simple I\'m sure, but driving me up the wall! There is a component that I use in my web application that identifies itself during a web request by adding the header \"X

相关标签:
7条回答
  • 2020-12-01 08:23

    Firstly you don't do this in your view. You do it in the controller and return a view model to the view so that the view doesn't need to care about custom HTTP headers but just displaying data on the view model:

    public ActionResult Index()
    {
        var xyzComponent = Request.Headers["xyzComponent"];
        var model = new MyModel 
        {
            IsCustomHeaderSet = (xyzComponent != null)
        }
        return View(model);
    }
    
    0 讨论(0)
提交回复
热议问题