Skip to main content

WEB API Throws “No Access-Control-Allow-Origin” Header is present on the requested resource.

This is the error occurs in the Client application that is consuming the WEB API. There might be two different reasons,

Web API by default doesn’t allow Service to be consumed from different domains.

  1.   RESOLVED BY CORS:

 [WEB API APPLICATION]

Open Tools ->   NuGet Package Manager - > Package Manager Console 
And install NuGet packages

Install-Package Microsoft.AspNet.WebApi.Cors

     GO to WebApiConfig.cs

          Add [ using System.Web.Http.Cors;  ] namespace in webapiConfig.cs file

               EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
       CONFIG.EnableCors(cors);


         First star resembles allow requests from all domains, else we can specify specific client URLS, separated by comma (,).

          Second star resembles allow requests for all the headers.

          Third star resembles allow requests for all the methods like POST, GET, PUT, DELETE, etc 


  2.   RESOLVED BY REMOVING HEADERS IN CLIENT REQUEST[AFTER CORS IMPLEMENTATION]

       
While no headers specified in WEB API, just try to remove the headers from the client side.


Comments

  1. thanks buddy, its worked for me, thanks a lot :)

    ReplyDelete
  2. Nice post. I study one thing tougher on completely different blogs everyday.This is a very nice blog that I will definitively come back to more times this year!
    play Battle for the Galaxy Break The Cup For boy play Rapunzel Fashionista Busy Day game

    ReplyDelete
  3. So first you soak your Red Wheat Berries, for 8-24 hours. You can buy Red Wheat Berries at your local health food store, often in the bulk section. And yes wheatgrass is gluten free. I too, was concerned, but after searching around and asking a licensed dietitian friend in the area, the grass itself does not contain any gluten, only the kernel, and in juicing wheatgrass you only juice the grass, so yay!
    kizi 2 unblocked
    friv jogos 2019
    play friv Games

    ReplyDelete

Post a Comment