【发布时间】:2019-06-30 00:06:45
【问题描述】:
我在服务器端项目中使用 Asp.Net Core Boilerplate 框架。 Angular 6 用于客户端项目。服务器端项目工作没有任何错误。 (显示 Swagger API - 并且 API 也在工作)
Angular 项目没有任何编译错误。使用 Google chrome 运行 Angular 项目时,(http://localhost:4200/) 它显示以下错误消息。
浏览器控制台显示如下:-
从源访问“http://server.projectName.lk//AbpUserConfiguration/GetAll”处的 XMLHttpRequest 'http://localhost:4200' 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查: 请求的资源上不存在“Access-Control-Allow-Origin”标头。
当点击“http://server.projectName.lk//AbpUserConfiguration/GetAll”链接时,它会在另一个选项卡中打开并显示以下错误,
非常感谢您解决此问题的想法..
注意:之前的任何问题都没有给我解决方案。
这是您收到的有关此问题的调试错误日志
> The thread 0x54b0 has exited with code 0 (0x0).
> Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request
> starting HTTP/1.1 OPTIONS
> http://localhost:21021/AbpUserConfiguration/GetAll 0
> Microsoft.AspNetCore.Cors.Infrastructure.CorsService:Information: CORS
> policy execution failed.
> Microsoft.AspNetCore.Cors.Infrastructure.CorsService:Information:
> Request origin http://localhost:4200 does not have permission to
> access the resource.
> Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request
> finished in 311.689ms 204
> Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information:
> Route matched with {action = "Index", controller = "Home", area = ""}.
> Executing action San.BA.Web.Host.Controllers.HomeController.Index
> (San.BA.Web.Host) The program '[21292] dotnet.exe' has exited with
> code -1 (0xffffffff).
【问题讨论】:
-
"server.projectName.lk/AbpUserConfiguration/GetAll" ,你能不能打开新标签并输入这个网址。
-
是的。但它给出了上述 404.0 错误消息..
-
您对默认 abp 项目模板进行了哪些更改?您是否发布了后端或从 VS 运行? 404,好像是请求的url错误,检查一下swagger中的方法,分享一下你是怎么从客户端发送请求的。
-
api AbpUserConfiguration/GetAll 方法在您的服务器端不存在。
-
嗨涛,我将现有的项目文件添加到下载的默认 Abp 项目模板中。我用 VS 运行了 Abp 项目..
标签: c# angular asp.net-core aspnetboilerplate