ASP NET MVC - "CORS" ERROR

Asked

Viewed 504 times

1

Hello,

I have a mistake and I can’t fix it. I have an ASP NET-MVC5 application and I carry a frame in my view that has some fonts, but they are giving the following error:

Access to font at 'https://www.fontteste/fonts/Bold.woff' from origin 'http://localhost:62688' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested Resource

I’ve already put in my "web config." the following excerpt, but without success:

 <httpProtocol>
     <customHeaders>
         <add name="Access-Control-Allow-Origin" value="*" />
         <add name="Access-Control-Allow-Headers" value="*" />
     </customHeaders>
 </httpProtocol>

Could you help me ?

  • Tries to change the file applicationHost.config placing your customHeader in a hidden folder of your project: "Seu_projeto.vs config applicationhost.config"

  • I include, but still the error remains :( <httpProtocol>&#xA; <customHeaders>&#xA;&#xA; <clear />&#xA; <add name="X-Powered-By" value="ASP.NET" />&#xA; <add name="Access-Control-Allow-Origin" value="*" />&#xA; <add name="Access-Control-Allow-Headers" value="*" />&#xA; <add name="Access-Control-Allow-Methods" value="GET,POST,PUT" />&#xA; </customHeaders>&#xA; <redirectHeaders>&#xA; <clear />&#xA; </redirectHeaders>&#xA; </httpProtocol>

  • Can you add more details (add controller and html to your page)? It will help the final answer, but, you have already tried to add the Microsoft.AspNet.Webapi.Cors package and add the attribute to your controller [Enablecors]?

1 answer

0

In Global.asax, enter the header in the "Application_presendrequestheaders"

protected void Application_PreSendRequestHeaders()
{
     this.Context.Response.Headers.Add("Access-Control-Allow-Headers", "*");
     this.Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.