Question:
Fixing CORS Issue with Angular App on IIS: POST Requests Failing

To fix this problem below Environment is required:


  • Frontend: Angular

  • Backend: Node.js, .NET,

  • Server URL (IIS): http://wapl8.ad.uclp:9091

  • Angular App URL (IIS): http://skw.uat.ad.uclp

  • Localhost works fine for all requests


Also, it is important to set a configuration to manage CORS.


Add the below code in your Startup ConfigureServices method to to set a confogiratin to manage CORS.


  services.AddCors(options =>

  {

      options.AddPolicy(name: "general",

          builder =>

          {

              builder.AllowAnyOrigin()

              .AllowAnyMethod().

              AllowAnyHeader();

          });

      options.AddPolicy(name: "restrictive",

          builder =>

          {

              builder.WithOrigins("http://Your frontEnd URL").

              WithMethods("GET", "POST", "PUT", "DELETE")

              .AllowAnyHeader();

          });

  });


Now add the below code in in Startup Configure Method:

app.UseCors("[general/restritive]; // or whatever name you use...

Is this example, "general" CORS configuration allows any origin from any host, and "restrictive" allows request just from the host you set


Answered by: >Stalky

Credit:> StackOverflow


Suggested blogs:

>How can I access specific data inside a JSON file on an Angular?

>HTTP request after another but only care about first one in Angular?

>Why am I getting unexpected parent reaction to child button Angular?

>How can I combine multiple HTTP calls in Angular using RxJS?

>Why Ng serve doesn't work in Angulars?

>How to use JSON:API along with Angular/RxJs?

>Why Ng server doesn't work in Angulars?

>How to operate data before return it using Angular16?

>How to Embed Node Red into existing Angular application?

>Why Angular routing with mat-toolbar is not working?




Submit
0 Answers

What Our Clients Say About Us

Client satisfaction is our ultimate goal. Here are some kind words of our precious clients they have used to express their satisfaction with our service.

Why Choose Us ?

We endow businesses with flexible engagement models based on their unique needs. Our strength lies in state-of-the-art technology and affordable consulting services. Try us for fast POCs, full-fledged applications, or technology consulting. Always available for your service.