简体   繁体   中英

Can't enable CORS globally in ASP.NET web API core

I configured the CorsAuthorizationFilterFactory like this

serviceCollection.AddMvc();
serviceCollection.Configure<MvcOptions>(options =>
{
    options.Filters.Add(new CorsAuthorizationFilterFactory(policyName));
});

But when I run the application received the issue:

System.TypeLoadException: 'Could not load type 'Microsoft.AspNetCore.Mvc.Cors.Internal.CorsAuthorizationFilterFactory' from assembly 'Microsoft.AspNetCore.Mvc.Cors, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'

I configured some dependencies like Microsoft.AspNetCore.Mvc.Cors but I have received the same issue. Could you give me any suggestions, please?

In ASP.NET Core 3.0, some pubinternal APIs that includes Microsoft.AspNetCore.Mvc.Cors.Internal are updated to be truly internal , which seems cause this issue.

If you want to migrate older version ASP.NET CORE App to 3.0 or above version, and enable CORS, you can refer to this doc about "Enable Cross-Origin Requests (CORS) in ASP.NET Core" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM