Dear Sir, I'm using asp.net zero for my below projects:
- Project have API Controller using .Netcore 2.2 (Backend)
- Project have Fontend using Angular 6 to call API in Project 1 (Frontend)
I add in devexpress report into my projects, and call the report from angular to .netcore project. However, there is an error message in .netcore logs file. Below is the error message:
INFO 2019-08-28 11:48:34,030 [34 ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'. INFO 2019-08-28 11:48:34,048 [34 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action FlexiCloud.Web.Host.Controllers.ReportDesignerController.GetReportDesignerModel (FlexiCloud.Web.Host) in 272.3821ms INFO 2019-08-28 11:48:34,049 [34 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 301.443ms 500 application/json; charset=utf-8 INFO 2019-08-28 11:48:34,049 [34 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HLPBD7I7OOVF", Request id "0HLPBD7I7OOVF:00000002": the application completed without reading the entire request body. INFO 2019-08-28 11:48:39,964 [37 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 POST http://localhost:91/DXXRDV application/x-www-form-urlencoded; charset=UTF-8 38 WARN 2019-08-28 11:48:39,964 [37 ] pNetCore.Cors.Infrastructure.CorsService - The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the policy by listing individual origins if credentials needs to be supported. INFO 2019-08-28 11:48:39,964 [37 ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful. INFO 2019-08-28 11:48:39,969 [37 ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {action = "Invoke", controller = "CustomWebDocumentViewer", area = ""}. Executing action FlexiCloud.Web.Host.Controllers.CustomWebDocumentViewerController.Invoke (FlexiCloud.Web.Host) INFO 2019-08-28 11:48:39,969 [37 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action FlexiCloud.Web.Host.Controllers.CustomWebDocumentViewerController.Invoke (FlexiCloud.Web.Host) in 0.1311ms ERROR 2019-08-28 11:48:39,970 [37 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HLPBD7I7OOVF", Request id "0HLPBD7I7OOVF:00000003": An unhandled exception was thrown by the application. System.InvalidOperationException: A CORS policy named '' could not be found. at Microsoft.AspNetCore.Mvc.Cors.CorsAuthorizationFilter.OnAuthorizationAsync(AuthorizationFilterContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at DevExpress.AspNetCore.Internal.BinaryStorageMiddleware.Invoke(HttpContext httpContext) at DevExpress.AspNetCore.Internal.ResourceManagerMiddleware.Invoke(HttpContext httpContext) at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore(HttpContext context) at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application) INFO 2019-08-28 11:48:39,971 [37 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 6.6044ms 500 INFO 2019-08-28 11:48:39,971 [37 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HLPBD7I7OOVF", Request id "0HLPBD7I7OOVF:00000003": the application completed without reading the entire request body. INFO 2019-08-28 12:09:18,982 [95 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 POST http://127.0.0.1:3753/iisintegration 0
Please advise. Thank you.
11 Answer(s)
-
0
Can you share a Demo project that reproduces the problem?
-
0
Please click below dropbox link to download my Demo project. FYI, these 2 projects running in 2 different port:
Demo project source code: ~~delete~~
Asp.net zero: http://localhost:91
Angular: http://localhost:4200
Thank you!
-
0
I will check it out.
-
0
Try changing AddPolicy to AddDefaultPolicy
options.AddPolicy( options.AddDefaultPolicy(
-
0
-
0
options.AddDefaultPolicy(builder => { //App:CorsOrigins in appsettings.json can contain more than one address with splitted by comma. builder .WithOrigins( // App:CorsOrigins in appsettings.json can contain more than one address separated by comma. _appConfiguration["App:CorsOrigins"] .Split(",", StringSplitOptions.RemoveEmptyEntries) .Select(o => o.RemovePostFix("/")) .ToArray() ) .SetIsOriginAllowedToAllowWildcardSubdomains() .AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin() //Added by YTTAN On 28-Aug-2019 .AllowCredentials(); });
-
0
Thanks maliming!
However, there is another error appear after amend as above.
In Angular, the error message showing "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:91/DXXRDV. (Reason: CORS header 'Access-Control-Allow-Origin' missing)", refer to below image:
While Asp.Net Core show error message "Castle.MicroKernel.ComponentNotFoundException: No component for supporting the service FlexiCloud.Web.Host.Controllers.CustomWebDocumentViewerController was found", please refer to attached logs file.
https://www.dropbox.com/s/xngoqde361csrxj/Logs.txt?dl=0
-
0
Make CustomWebDocumentViewerController inherit the ITransientDependency interface.
[EnableCors] [ApiExplorerSettings(IgnoreApi = true)] [Route("DXXRDV")] public class CustomWebDocumentViewerController : WebDocumentViewerController, ITransientDependency
-
0
Thanks Maliming!
Another error message in log file "System.InvalidOperationException: A CORS policy named 'localhost' could not be found."
-
0
hi You can try to keep your original Cors settings unchanged, and add the default cors policy. That is, there are both the default CORS policy and Zero's default localhost policy.
You can refer to the documentation for a more detailed understanding of CORS. https://docs.microsoft.com/en-us/aspnet/core/security/cors
-
0
magicang can you plz send me the demo to [email protected]