I am passing some header values to my API call in an Angular application:
httpOptions = {
headers: new HttpHeaders({
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"xibm-clientid": "Test"
})
};
submitSomething(myData: IMyData): Observable<any> {
return this.httpClient
.post<any>(apiURL, JSON.stringify(myData), this.httpOptions)
.pipe(catchError(this.errorHandler));
}
The request is getting redirected to my backend API (ASP.NET 3.1 Core API) and I am checking the request header as follows:
string apicClientId = context.Request.Headers["xibm-clientid"].ToString();
The header "xibm-clientid" is not present in context.Request.Headers list.
Note:
I am checking this header in a custom middleware rather than in Controller level:
public class CheckHeadersMiddleware
{
private readonly RequestDelegate _next;
public CheckHeadersMiddleware(RequestDelegate next)
{
_next = next ?? throw new ArgumentNullException(nameof(next));
}
public async Task Invoke(HttpContext context)
{
string apicClientId = context.Request.Headers["xibm-clientid"].ToString();
}
}
I can read this header when it hits the controller but I don't want to do that because I want to check the header before the controller is called. So why the header is not appearing in the middleware level?
Is something I am missing here?



