Our project consists of an MVC area which handles authentication/authorization and rendering of pages, and an API area which also requires authentication/authorization and sends data to the page. We decided to go stateless for the server, so each request must include the authorization header with the user's credentials.
I accomplish this with the API calls with xhr.setRequestHeader('Authorization', 'Bearer ' + authCookie);
in jquery's beforeSend
, however I am unsure how to do this for the MVC side (each time you click a link or enter a URL, the request should include the Authorization header). Currently I'm doing this inside Application_BeginRequest
and setting Request.Headers["Authorization"] = Request.Cookies["auth"];
, but I want the Authorization header to be in the initial request, and not just tacked on after the request has been sent.