Q: Access to fetch at 'https://localhost:5099/api/catalog-items' from origin 'https://localhost:44315' has been blocked by CORS policy: I am studying .Net 6 reference app EShopOnWeb from Microsoft using Visual Studio 2022.I have not changed any thing from the original installation. I am able to start both the PublicAPI and Web project. I have difficulty in using the BlazorAdmin app. Specifically, After I log in as Admin, I am not able to view the Manage Product Catalog page. It is blank. When view the Network traffic in Developer Tools, it gave me 7 errors.
Access to fetch at 'https://localhost:5099/api/catalog-items' from origin 'https://localhost:44315' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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.ne of them is:
This is the reference application. I have not changed code.  Could anyone point me the right direction on what to do?
Thanks

A: Its a CORS error on your Api CORS policy, which denies the request from a different origin.
You can allow this by updating the CORS policy to allow any origin in your Program.cs:
builder.Services.AddCors(options =>
{
    options.AddPolicy(name: CORS_POLICY,
                      builder =>
                      {
                          builder.WithOrigins(baseUrlConfig.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'));
                          builder.AllowAnyMethod();
                          builder.AllowAnyHeader();
                          builder.AllowAnyOrigin();//Add this line
                      });
});


A: For future reference, I resolved the issue by installing this package to the PublicAPI project:
Microsoft.AspNetCore.Cors

Without making any other change, I am able to view the page at https://localhost:44315/Admin without any errors. I can see a grid of products, instead of an empty page.
Install-Package Microsoft.AspNetCore.Cors

