我正在尝试将我的Web Api2迁移到ASP.NET核心web api项目.在我的项目中,我们使用的是EnableCors功能.
我在Microsoft网站上找到了这个文档,我将其用作参考 – https://docs.asp.net/en/latest/security/cors.html
正如“在MVC中启用CORS”一节中所述,我试图在这样的ConfigureServices menthod中全局启用cors –
services.Configure<Mvcoptions>(options => { options.Filters.Add(new CorsAuthorizationFilterFactory("AllowSpecificOrigin")); });
但是,我收到了这个我无法理解的错误 –
The call is ambiguous between the following methods or properties:
‘Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection,
System.Action)’ and
‘Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection,
System.Action)’
请参阅错误截图 – ERROR scrrenshot
有谁能告诉我如何在我的ASP.NET核心WebApi项目中全局启用CORS?
Project.json:
{ "userSecretsId": "aspnet5-MVC6","version": "1.4.0-*","buildOptions": { "emitEntryPoint": true,"preserveCompilationContext": true },"dependencies": { "Microsoft.ApplicationInsights.AspNetCore": "1.0.0","Microsoft.AspNetCore.Authentication.Cookies": "1.0.0","Microsoft.AspNetCore.Diagnostics": "1.0.0","Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0","Microsoft.AspNetCore.Identity": "1.0.0","Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0","Microsoft.AspNetCore.Mvc": "1.0.0","Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0","Microsoft.AspNet.Cors": "6.0.0-rc1-final","Microsoft.AspNetCore.Server.IISIntegration": "1.0.0","Microsoft.AspNetCore.Server.Kestrel": "1.0.0","Microsoft.AspNetCore.StaticFiles": "1.0.0","Microsoft.EntityFrameworkCore": "1.0.0","Microsoft.EntityFrameworkCore.sqlServer": "1.0.0","Microsoft.Extensions.Configuration.CommandLine": "1.0.0","Microsoft.Extensions.Configuration.FileExtensions": "1.0.0","Microsoft.Extensions.Configuration.Json": "1.0.0","Microsoft.Extensions.Configuration.UserSecrets": "1.0.0","Microsoft.Extensions.Logging": "1.0.0","Microsoft.Extensions.Logging.Console": "1.0.0","Microsoft.Extensions.Logging.Debug": "1.0.0","Microsoft.VisualStudio.Web.browserLink.Loader": "14.0.0" },"tools": { "BundlerMinifier.Core": "2.0.238","Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final","Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final","Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final" },"frameworks": { "netcoreapp1.0": { "imports": [ "dnxcore50" ],"dependencies": { "Microsoft.NETCore.App": { "type": "platform","version": "1.0.0" } } },"net461": { "dependencies": { "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final" } } },"publishOptions": { "exclude": [ "**.user","**.vspscc","wwwroot","node_modules" ] },"scripts": { "prepublish": [ "npm install","bower install","gulp clean","gulp min" ] } }