In a controller action, response header is set like this:
HttpContext.Response.AddHeader("key", "value");
In rendered view, Response.Headers[“key”] seems to be null (btw in ajax requests, header is set and retrieved without any problems). Is there any special reason for this or is this a silly bug in my code?
You can only add response headers but you cannot read them unless you are running in IIS 7 integrated pipeline mode. When running in standard model HTTP response headers are sent at a later stage by the time you try to read them in your code. This has been stated in the documentation:
This being said, all that a view should access is a view model, not response headers. So in your controller action you will build a view model containing all the information that the view will require and pass it to the view for consumption. Remember: a view doesn’t pull data, a view uses data that it is being handled from the controller under the form of a view model.