An Azure Website I am working on inspects custom headers of incoming requests to decide what to do with the request internally. The request is being sent/received by the website server with the customer headers:
X-HEADER-1: ...
X-HEADER-2: ...
among other standard and non-standard headers.
I verified this by inspecting the FREB logs and looking at GENERAL_REQUEST_HEADERS, which correctly includes my custom headers.
When the application receives the request, those custom headers are not there. I explicitly check for one of them then throw and dump all available headers in the error message.
I have read around that Application Request Routing module can drop these headers. I tried adding this to the website's web.config but still doesn't work:
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="HTTP_X_HEADER_1" />
<add name="HTTP_X_HEADER_2" />
</allowedServerVariables>
</rewrite>
</system.webServer>
Any idea how I can whitelist my headers to let ARR/Azure let them through?
Update 1
Here is some more info.
- This works locally on my dev box. I set up the site in IIS and point it to the project folder and headers are coming in and processed as expected.
- It is an ASP.NET MVC website.
Here is the part of the code that reads the header. Again, this works locally.
public class BaseController : Controller { public AppControllerBase(...) { }
protected override void Initialize(RequestContext requestContext) { var header1Value = requestContext.HttpContext.Request.Headers["X-HEADER-1"]; if (string.IsNullOrEmpty(header1Value)) { var stringBuilder = new StringBuilder(); // append all headers to stringBuilder var errorMessage = string.Format("SiteId header is not set. Headers: {0}", stringBuilder); throw new HttpRequestException(errorMessage); } base.Initialize(requestContext); } ...
}
Update 2
I just deployed the same app as an azure cloud service and it worked well. The headers were received and the app read them successfully. Something with web apps is not letting those headers through.
curl -I https://<mySiteName>.azurewebsites.net
returns a 500 and runningcurl -I -H "X-HEADER-1: random-value" https://<mySiteName>.azurewebsites.net
returns 200. you do see your headers in the FREB log, right? – ahmelsayed