ngx扩展的pdf-viewer cors cors误差Angular和asp.net core
我试图使用ASP.NET Core作为后端的Angular中的NGX-Extended-extended-extended-pdf-ciewer查看PDF文件。这是我的模板:
<ngx-extended-pdf-viewer [src]="pdfsrc"
[height]="'95%'"
useBrowserLocale="true"
[textLayer]="true"
[showHandToolButton]="true"
>
</ngx-extended-pdf-viewer>
在我的component.ts
pdfsrc: any;
this.pdfsrc = this.children.studyPath;
this.sanitizer.bypassSecurityTrustResourceUrl(this.pdfsrc)
cors策略中,在ASP.NET核心中,
app.UseCors(policy => policy.AllowAnyHeader().AllowAnyMethod().WithOrigins("https://localhost:4200"));
中获得此错误访问
我在'https:// localhost:5001/childstudyreportfolder/7a6c78dd-aaa3a-46db-bbea-bbea-37a45678484d1a 。 pdf'从ouncon'https:// localhost:4200'已被CORS策略阻止:在请求的资源上没有“访问conscept-control-allow-origin”标头。如果不透明的响应满足您的需求,请将请求模式设置为“无核”,以通过禁用CORS来获取资源。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是app.usestaticfiles();
在启动cs中使用app.usecors()之前放置;
在app.usecors()之后放置app.usestaticfiles()之后;
我清除了所有缓存数据,并且有效。谢谢
the issue was that app.UseStaticFiles();
was placed before use app.UseCors() in the startup.cs;
After placing app.UseStaticFiles() after app.UseCors();
I cleared all cache data and it works. Thanks
如果您可以显示更多详细信息,可能会有所帮助
在ASP.NET Core中启用CORS,您应该按以下设置设置:
注意中间件的顺序,
app.usecors(myallowspecificorigins);
应该在app.userouting();
后面。在app.useuthentication();
添加
[enablecors]
与外部文档相关:
It may help if you could show more details,
Enable CORS in ASP.NET Core,you should set as below :
notice the order of the middleware,
app.UseCors(MyAllowSpecificOrigins);
should behindapp.UseRouting();
and beforeapp.UseAuthentication();
add
[EnableCors]
on your controllerThe offcial document related:
https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0