Random error with Filemanager

Hi

I have problem with Blazor Wasm using FileManager component.

The error is the following

Access to fetch at 'https://myurlfromapitest/api/FileManager/FileOperations?t_id=/14' from origin 'https://www.xxxxxxxxx.com' 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.

This error does not always happen and is random

Please help!

3 Replies 1 reply marked as answer

IL Indhumathy Loganathan Syncfusion Team May 17, 2021 09:58 AM UTC

Hi Jose, 
 
Thanks for contacting Syncfusion support. 
 
We have validated the reported issue in File Manager component. This issue occurs due to the cross origin requests are not enabled in your sample, so the browser stops API calls to server. In the API controller, you need to enable CORS (i.e) allow cross origin requests. You can configure CORS policy at application startup in the ConfigureServices method for File Manager component. Kindly refer to the following code snippet. 
 
Startup.cs 
 
public void ConfigureServices(IServiceCollection services) 
        { 
            ...... 
            services.AddCors(); 
        } 
……….. 
……….. 
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 
{ 
    ...... 
    app.UseCors(builder => 
        builder.WithOrigins("http://example.com")); 
} 
 
Please find the sample from below link. 
 
 
Also, refer to the following blog for more details on this.  
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Indhumathy L 


Marked as answer

JL jose luis barajas May 17, 2021 08:43 PM UTC

Hi

Yes I have this configuration
the value of validOrigin variable is obtained from appsettings.json

But as I tell you, this error is random!

  app.UseCors(policy =>
            {
                var validOrigin = Configuration["Website_Host_Origin"].ToString();
                policy.WithOrigins(
                    validOrigin, 
                    "http://localhost:8081",
                    );
                policy.AllowAnyMethod();
                policy.AllowAnyHeader();
                policy.AllowCredentials();
            });



IL Indhumathy Loganathan Syncfusion Team May 18, 2021 04:42 PM UTC

Hi Jose, 
 
We have validated your reported issue with the shared details. We have run the ASP.Net core physical service provider as a separate project and mapped it with Blazor File Manager application. After enabled the CORS in Startup.cs, we are unable to replicate the reported error in our end. Please check the below code snippets tried in our end. 
 
appsettings.json 
{ 
  "Logging": { 
    "LogLevel": { 
      "Default": "Warning" 
    } 
  }, 
  "AllowedHosts": "*", 
  "Website_Host_Origin": http://localhost:53920 
} 
 
Startup.cs 
app.UseCors(policy => 
{ 
    var validOrigin = Configuration["Website_Host_Origin"].ToString(); 
    policy.WithOrigins( 
        validOrigin, 
        http://localhost:8081 
        ); 
    policy.AllowAnyMethod(); 
    policy.AllowAnyHeader(); 
    policy.AllowCredentials(); 
}); 
 
We need some additional details on the following from your end to proceed further on this.  
 
1.      Service provider used in your project . 
2.      Whether you have configured CORS in your controller at required places. 
3.      Whether the proper port address is mapped in CORS at your end.  
4.      If possible, revert by modifying the previous sample to replicate the issue else share us a video footage of your issue. 
 
These details would help us to assist you promptly. Meanwhile, we suggest you to try out the below mentioned ways to resolve the issue. 
 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Indhumathy L 


Loader.
Up arrow icon