【发布时间】:2021-03-24 07:45:47
【问题描述】:
我正在将 Piranha CMS (v8.4) 集成到现有的 ASP .NET Core 3.1 项目中。我已经让 Piranha 工作了,但我得到一个异常,表明 CORS 设置不正确。
我已设法将问题的根源追溯到 Piranha 中间件的配置。 options.UseManager() 行是导致问题的原因,当 options.UseManager() 行被注释掉时,CORS 中间件按预期运行。
app.UsePiranha(options =>
{
options.UseManager();
options.UseTinyMCE();
options.UseIdentity();
});
InvalidOperationException: Endpoint contains CORS metadata, but a middleware was not found that supports CORS. Configure your application startup by adding app.UseCors() inside the call to Configure(..) in the application startup code. The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...).
我的 CORS 策略是这样配置的。在UsePiranha 之前或之后调用没有区别:
// global cors policy
app.UseCors(x => x
.AllowAnyMethod()
.AllowAnyHeader()
.SetIsOriginAllowed(origin => env.IsDevelopment()) //any origin in dev
.AllowCredentials());
`
【问题讨论】:
标签: .net-core cors asp.net-core-3.1 piranha-cms