React+ASP.NET.Core : No 'Access-Control-Allow-Origin' header is present on the requested resource

前端 未结 3 1024
星月不相逢
星月不相逢 2020-12-29 08:17

Actually this is not a duplication post,I know a part of the title asked many times in stackoverflow community, I read all posts, and answers, but I think m

3条回答
  •  温柔的废话
    2020-12-29 09:20

    After two difficult days finally I found out how can I fix my problem. Actually one of your comment was a nice clue for me.

    @kirk-larkin said:

    The response had HTTP status code 500 is key here. When there's an exception in your ASP.NET Core project, the CORS headers are cleared. You should try and find out why an exception is being thrown.

    I traced my code many times, then i found out I forget to register a service which I used in my controller in Startup.cs.

    I called these below code in Startup.cs and my problem solved.

    services.AddScoped();
    

提交回复
热议问题