Base solution for your next web application
Open Closed

No 'Access-Control-Allow-Origin' header present when using Host #6352


User avatar
0
alexanderpilhar created

6.5.0, Angular, .Net Framework deployed to azure

I have a rather strange issue here ...

I have a service for file-management, a page 'file-management' that communicates with the service, as well as a modal that can be used by other components. When using the file-management component, the first request is fired to get meta-data to display a list of files and folders.

When I'm using a tenant-account everything is working fine.

But when I'm using a host-account I get a an error related to CORS (browser console): Access to fetch at 'https://projectname.azurewebsites.net/api/services/app/FileManagerBackend/GetAllAsync?Name=' from origin 'https://projectname-be.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Next thing that happens is the application crashing (server-side) resulting in following error message (browser console): GET https://projectname.azurewebsites.net/api/services/app/FileManagerBackend/GetAllAsync?Name= 504 (Gateway Timeout) and ERROR Error: An unexpected server error occurred.

After a while the application is back running fine.

Also, this does not happen in development environment (localhost).


9 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Why is the sub-domain different?

  • User Avatar
    0
    alexanderpilhar created

    Hi @aaron!

    projectname.azurewebsites.net is the .Net application projectname-be.azurewebsites.net is the angular client (one of three)

  • User Avatar
    0
    alexanderpilhar created

    This is what azure log stream has to say about it:

    HTTP Error 502.3 - Bad Gateway
    The connection with the server was terminated abnormally
    
    Most likely causes:
    - The CGI application did not return a valid set of HTTP errors.
    - A server acting as a proxy or gateway was unable to process the request due to an error in a parent gateway.
    
    Things you can try:
    - Use DebugDiag to troubleshoot the CGI application.
    - Determine if a proxy or gateway is responsible for this error.
    
    Detailed Error Information:
    Module
       AspNetCoreModuleV2
    Notification
       ExecuteRequestHandler
    Handler
       aspNetCore
    Error Code
       0x80072efe
    Requested URL
       https://projectname:80/api/services/app/FileManagerBackend/GetAllAsync?Name=
    Physical Path
       D:\home\site\wwwroot\api\services\app\FileManagerBackend\GetAllAsync
    Logon Method
       Anonymous
    Logon User
       Anonymous
    
    More Information:
    This error occurs when a CGI application does not return a valid set of HTTP headers, or when a proxy or gateway was unable to send the request to a parent gateway. You may need to get a network trace or contact the proxy server administrator, if it is not a CGI problem. 
    
  • User Avatar
    0
    alexanderpilhar created

    This is from App_Data\Logs\Logs.txt:

    INFO  2019-01-25 07:23:39,777 [3    ] ore.Mvc.Internal.ControllerActionInvoker - Executed action CompanyName.ProjectName.Web.Controllers.HomeController.Index (CompanyName.ProjectName.Web.Host) in 7.5609ms
    INFO  2019-01-25 07:23:39,777 [3    ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'CompanyName.ProjectName.Web.Controllers.HomeController.Index (CompanyName.ProjectName.Web.Host)'
    INFO  2019-01-25 07:23:39,777 [3    ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 77.0956ms 302 
    INFO  2019-01-25 07:24:00,718 [6    ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS http://projectname.azurewebsites.net/api/services/app/FileManagerBackend/GetAllAsync?Name=  
    INFO  2019-01-25 07:24:00,718 [6    ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-01-25 07:24:00,734 [6    ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 1.7097ms 204 
    INFO  2019-01-25 07:24:00,796 [18   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://projectname.azurewebsites.net/api/services/app/FileManagerBackend/GetAllAsync?Name=  
    INFO  2019-01-25 07:24:00,796 [18   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-01-25 07:24:00,796 [18   ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token.
    WARN  2019-01-25 07:24:00,796 [18   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-01-25 07:24:00,796 [18   ] calization.RequestLocalizationMiddleware - AbpUserRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    WARN  2019-01-25 07:24:00,796 [18   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported cultures 'null'.
    WARN  2019-01-25 07:24:00,796 [18   ] calization.RequestLocalizationMiddleware - AbpDefaultRequestCultureProvider returned the following unsupported UI Cultures 'null'.
    INFO  2019-01-25 07:24:00,796 [18   ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'CompanyName.ProjectName.Backend.FileManagement.FileManagerBackendAppService.GetAllAsync (CompanyName.ProjectName.Application)'
    INFO  2019-01-25 07:24:00,812 [18   ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {area = "app", action = "GetAllAsync", controller = "FileManagerBackend"}. Executing action CompanyName.ProjectName.Backend.FileManagement.FileManagerBackendAppService.GetAllAsync (CompanyName.ProjectName.Application)
    INFO  2019-01-25 07:24:00,812 [18   ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
    INFO  2019-01-25 07:24:00,812 [18   ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method CompanyName.ProjectName.Backend.FileManagement.FileManagerBackendAppService.GetAllAsync (CompanyName.ProjectName.Application) with arguments (CompanyName.ProjectName.Backend.FileManagement.Dto.FileObjectFilterBackendDto) - Validation state: Valid
    DEBUG 2019-01-25 07:24:15,015 [1    ] Abp.Modules.AbpModuleManager             - Loading Abp modules...
    DEBUG 2019-01-25 07:24:15,124 [1    ] Abp.Modules.AbpModuleManager             - Found 23 ABP modules in total.
    DEBUG 2019-01-25 07:24:15,190 [1    ] Abp.Modules.AbpModuleManager             - Loaded module: CompanyName.ProjectName.Web.Startup.ProjectNameWebHostModule, CompanyName.ProjectName.Web.Host, Version=6.5.0.0, Culture=neutral, PublicKeyToken=null
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    @alexanderpilhar

    Are there any ERROR line on the Logs.txt ?

  • User Avatar
    0
    alexanderpilhar created

    Hi @ismcagdas !

    Nope, not at all ...

    Anyway, right now it is not that important, because use-cases for host to use file-management are not to be implemented soon. And for tenants everything is working fine.

    It's just that, I can't explain what is going on in this service ... why would it work for tenants but not for host users? There is really nothing special in there.

    Have a nice weekend @all

  • User Avatar
    0
    alexanderpilhar created

    FYI, I can trigger this error using postman.

    Calling service as Host:

    Calling service as Tenant:

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    This error message should be logged somewhere. If you can't find it in Logs.txt, you can check event viewer of Windows.

  • User Avatar
    0
    alexanderpilhar created

    Finally, I was able to figure it out : )

    Logs didn't help much, though. Except for telling me that it might not be a problem with the application itself (since I couldn't find any messages about errors). Anyway, I learned about logging in Azure and how to analyze it, which is nice.

    The fact that there was just one service method failing (and only for host users) got me thinking, though: What if there is something wrong with the data that I'm trying to request!?

    And there it was, right in front of me all the time: a referetial integrity issue :D

    I deleted the entry that was causing the problem and now everything works fine. I just need to make sure this doesn't happen again.

    Closing this now - thank you for trying to help me!