I have two VS projects : one exposing MVC5 controllers, the other being an angular client. I want the angular client to be able to query the controllers. I read numerous thr
I tried in my .net c# mvc app and client app in angular 8 but it is not working. IN web.config, i added
In global.axax.cs file also, i added
void MvcApplication_AuthenticateRequest(object sender, EventArgs e)
{
Context.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:4200");
}
but it is not working. In chrome in response header it does show as :
Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: http://localhost:4200 Access-Control-Allow-Origin: http://localhost:4200
but in request header it shows as
Access-Control-Request-Headers: access-control-allow-origin,content-type,x-iphoneclientid
whereas it needs to have like
x-iphoneclientid : 8E72FF50-548B
since x-iphoneclientid is the token i validate in my filter class as
protected override System.Threading.Tasks.Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
if (request == null || request.RequestUri == null)
{
return null;
}
// Write your Authentication code here
IEnumerable monsterApiKeyHeaderValues = null;
// Checking the Header values
if (request.Headers.TryGetValues("x-iphoneclientid", out monsterApiKeyHeaderValues))
and above condition does not find so it rejects it and it does not reach to controller.
I even have put following in my controller
[EnableCors("", "", "*")]
can you guide please
Thanks