为什么在 ASP.NET 5 上更新到 beta8 后 Cors 不起作用?
Why Cors doesn't work after update to beta8 on ASP.NET 5?
我已将 ASP.NET 5 更新为 beta8,并将依赖项更改为 "Microsoft.AspNet.Cors": "6.0.0-beta8"。
之后我在
行的 ConfigureServices 中收到错误
services.ConfigureCors(options => { options.AddPolicy("AllowAllOrigins", builder => builder.AllowAnyOrigin()); });
Error CS1929 'IServiceCollection' does not contain a definition for
'ConfigureCors' and the best extension method overload
'MvcCorsMvcCoreBuilderExtensions.ConfigureCors(IMvcCoreBuilder,
Action)' requires a receiver of type
'IMvcCoreBuilder' WebAPI.DNX 4.5.1 C:...\Startup.cs
如何修复它并激活 CORS?
方法名称已更改为AddCors
。
所以现在你应该使用 services.AddCors()
而不是 services.ConfigureCors()
:
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins", builder => builder.AllowAnyOrigin());
});
我已将 ASP.NET 5 更新为 beta8,并将依赖项更改为 "Microsoft.AspNet.Cors": "6.0.0-beta8"。
之后我在
行的 ConfigureServices 中收到错误services.ConfigureCors(options => { options.AddPolicy("AllowAllOrigins", builder => builder.AllowAnyOrigin()); });
Error CS1929 'IServiceCollection' does not contain a definition for 'ConfigureCors' and the best extension method overload 'MvcCorsMvcCoreBuilderExtensions.ConfigureCors(IMvcCoreBuilder, Action)' requires a receiver of type 'IMvcCoreBuilder' WebAPI.DNX 4.5.1 C:...\Startup.cs
如何修复它并激活 CORS?
方法名称已更改为AddCors
。
所以现在你应该使用 services.AddCors()
而不是 services.ConfigureCors()
:
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins", builder => builder.AllowAnyOrigin());
});