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
  4. It's very useful blog post with inforamtive and insightful content and i had good experience with this information.I have gone through CRS Info Solutions Home which really nice. Learn more details About Us of CRS info solutions. Here you can see the Courses CRS Info Solutions full list.Find the best Hadoop Training with great faculty. Go to know about crs info solutions Workday Training program.

    ReplyDelete
  5. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    workday studio online training
    best workday studio online training
    top workday studio online training

    ReplyDelete

Post a Comment