Base solution for your next web application
Open Closed

CORS policy 'Access-Control-Allow-Origin' problem #7592


User avatar
0
Riaan.Smit created

Hi,

I'm sorry to be asking this question again. Seems like it's been answered 10x before. I tried to follow all the previous answers, but I'm still stuck on getting the Cors policy error on most (not all) updates/deletes.

For example, I can add a new Organization Unit, but I can't delete it.

I checked both appsettings.json, and appsettings.Production.json, as below, and they seem fine. I've also enabled and disabled WebDAV on both Client and Server sites, and forced a iisreset to ensure.

Both app pools are set to "No Managed Code", and Integrated.

The Client site (Angular) is at: http://localhost:4200 The Server site (.Net Core) is at: http://localhost:9901

appsettings.json: "App": { "ServerRootAddress": "http://localhost:9901/", "ClientRootAddress": "http://localhost:4200/", "CorsOrigins": "http://localhost:4200,http://localhost:9901", "SwaggerEndPoint": "/swagger/v1/swagger.json", "AllowAnonymousSignalRConnection": "true" }

appsettings.Production.json: "App": { "ServerRootAddress": "http://localhost:9901/", "ClientRootAddress": "http://localhost:4200/", "CorsOrigins": "http://localhost:4200,http://localhost:9901" }

and in my Client site, I have this in the appconfig.json and appconfig.production.json:

"remoteServiceBaseUrl": "http://localhost:9901", "appBaseUrl": "http://localhost:4200",

I'm completely out of ideas. Any help would be greatly appreciated!

Update:

I'm note sure if this is of any help. Below is the log after trying to update a tenant's settings, and getting the Cors error:

The actual error: Access to XMLHttpRequest at 'http://localhost:9901/api/services/app/TenantSettings/UpdateAllSettings' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Log details: INFO 2019-09-03 20:41:18,935 [104 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS http://localhost:9901/api/services/app/TenantSettings/UpdateAllSettings
INFO 2019-09-03 20:41:18,935 [104 ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful. INFO 2019-09-03 20:41:18,935 [104 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 0.8894ms 204


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    The actual error: Access to XMLHttpRequest at 'http://localhost:9901/api/services/app/TenantSettings/UpdateAllSettings' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    Is this request http verb Post or Put?

  • User Avatar
    0
    Riaan.Smit created

    Hi, I tried a simpler function. When trying to update my profile settings, once logged in, I get the same error:

    For the error: PUT http://localhost:9901/api/services/app/Profile/UpdateCurrentUserProfile net::ERR_ABORTED 405 (Method Not Allowed)

    Access to XMLHttpRequest at 'http://localhost:9901/api/services/app/Profile/UpdateCurrentUserProfile' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

    This is the newtork details:

    General: Request URL: http://localhost:9901/api/services/app/Profile/UpdateCurrentUserProfile Request Method: PUT Status Code: 405 Method Not Allowed Remote Address: [::1]:9901 Referrer Policy: no-referrer-when-downgrade

    Reponse Headers: Allow: GET, HEAD, OPTIONS, TRACE Cache-Control: private Content-Length: 5356 Content-Type: text/html; charset=utf-8 Date: Wed, 04 Sep 2019 07:18:21 GMT Server: Microsoft-IIS/8.5

  • User Avatar
    0
    maliming created
    Support Team

    see https://docs.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications

  • User Avatar
    0
    Riaan.Smit created

    Hi @Maliming,

    I resolved the issue by following the advice on on https://docs.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications

    I added the <remove name="WebDAV" />, line to my web.config, but I also had to manually remove the WebDav modules listed under Handler Mappings and ISAPI Filters in IIS. Once I did that, the functions started to work.