ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,749 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm using Asp.net Core 6 with 2 projects:
I'm getting this error, but I don't know how to fix it, I hope someone can help.
Access to font at 'https://localhost:6402/theme/01/plugins/global/fonts/@fortawesome/fa-solid-900.woff2' from origin 'https://localhost:6403' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
In the static project I added:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(
policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
var app = builder.Build();
app.UseStaticFiles();
app.UseCors();
app.MapGet("/", () => "Running...!");
app.Run();
and i also tried with web.config
<?xml version="1.0" encoding="UTF-8"?>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
But it still doesn't work, what should I do now?
I solved the problem, just move app.UseCors(); above app.UseStaticFiles();
var app = builder.Build();
app.UseCors();
app.UseStaticFiles();
app.MapGet("/", () => "Running...!");
app.Run();