HI I deployed the server and angular to 2 different sub-domain
When i access the angular site, i get the following error.
Failed to load http://sandboxserver.xxxxxx.com/AbpUserConfiguration/GetAll: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://sandboxclient.xxxxxxxx.com' is therefore not allowed access.
Here are my config details: <ins>On server side: - appsettings.json (same for production.json and sandbox.json)</ins>
{
"ConnectionStrings": {
"Default": "Data Source=xxxxxxx"
},
"App": {
"ServerRootAddress": "http://sandboxServer.xxxxxx.com",
"ClientRootAddress": "http://sandboxClient.xxxxxx.com",
"CorsOrigins": "http://sandboxClient.xxxxx.com, http://*"
}
}
On client side appconfig.json (same for appconfig.production.json)
{
"remoteServiceBaseUrl": "http://sandboxServer.xxxxxxxx.com",
"appBaseUrl": "http://sandboxClient.xxxxxxxxx.com",
"localeMappings": [
{
"from": "pt-BR",
"to": "pt"
},
{
"from": "zh-CN",
"to": "zh"
},
{
"from": "he-IL",
"to": "he"
}
]
}
I have also tried with the custom header on the server side web.config with the following and still doesn't work.
<add name="Access-Control-Allow-Headers" value="*" />
What am i missing?
15 Answer(s)
-
0
as I see from your configuration, your both subdomains are the same "http://sandboxServer.xxxxxx.com", right?
-
0
No, both are different.
sandboxServer.domain.com sandboxClient.domain.com
-
0
Could you check App_Data/Logs.txt file for error details.
-
0
I do not have any app data folder.
-
0
<cite>kumaran: </cite> I do not have any app data folder.
Please check the Log files under App_Data folder in the directory of your ..Web.Host project
-
0
The error is happening in the server after the deployment and not in my local machine. I do not see any folder called "App_data"
-
0
Ok after giving read/write permission to asp.net, i see the log file and here is the details of the log .... ... DEBUG 2018-08-26 22:41:35,300 [1 ] Abp.BackgroundJobs.BackgroundJobManager - Start background worker: Abp.BackgroundJobs.BackgroundJobManager DEBUG 2018-08-26 22:41:35,382 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Found 2 classes define auto mapping attributes DEBUG 2018-08-26 22:41:35,384 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Events.Web.Models.TokenAuth.ExternalLoginProviderInfoModel DEBUG 2018-08-26 22:41:35,390 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Events.Friendships.Cache.FriendCacheItem DEBUG 2018-08-26 22:41:42,492 [1 ] enancy.SubscriptionExpirationCheckWorker - Start background worker: Events.MultiTenancy.SubscriptionExpirationCheckWorker DEBUG 2018-08-26 22:41:42,495 [1 ] cy.SubscriptionExpireEmailNotifierWorker - Start background worker: Events.MultiTenancy.SubscriptionExpireEmailNotifierWorker INFO 2018-08-26 22:41:43,892 [3 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS <a class="postlink" href="http://server-001-site1.itempurl.com/AbpUserConfiguration/GetAll">http://server-001-site1.itempurl.com/Ab ... ion/GetAll</a>
INFO 2018-08-26 22:41:43,976 [3 ] pNetCore.Cors.Infrastructure.CorsService - Policy execution failed. INFO 2018-08-26 22:41:43,977 [3 ] pNetCore.Cors.Infrastructure.CorsService - Request origin <a class="postlink" href="http://client-001-site1.gtempurl.com">http://client-001-site1.gtempurl.com</a> does not have permission to access the resource. INFO 2018-08-26 22:41:44,090 [3 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 204.2933ms 204 -
0
and here is my appsettings.json on server
"App": { "ServerRootAddress": "http://server-001-site1.itempurl.com", "ClientRootAddress": "http://client-001-site1.gtempurl.com", "CorsOrigins": "http://client-001-site1.gtempurl.com" },
-
0
see the below doc if anything is changed or misconfigured in your code base. <a class="postlink" href="https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-2.1">https://docs.microsoft.com/en-us/aspnet ... etcore-2.1</a>
-
0
I did not change any code in startup.cs which has the corsorgin code //Configure CORS for angular2 UI services.AddCors(options => { options.AddPolicy(DefaultCorsPolicyName, 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() ) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); });
-
0
I did not change any code in startup.cs which has the corsorgin code
//Configure CORS for angular2 UI services.AddCors(options => { options.AddPolicy(DefaultCorsPolicyName, 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() ) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); });
-
0
Can someone please help me. I am stuck here and not able to run my angular site after deploying. thanks
-
0
Did you install .NET Core Hosting Bundle? <a class="postlink" href="https://www.microsoft.com/net/download/thank-you/dotnet-runtime-2.1.3-windows-hosting-bundle-installer">https://www.microsoft.com/net/download/ ... -installer</a>
And is there any error in your logs.txt or in Windows Events? run the command eventvwr to check Event Viewer
-
0
I have already installed the hosting bundle.
I fixed the error by hard coding the url in the statup.cs. I have double checked the settings.json and everything seems to be correct.
services.AddCors(options => { options.AddPolicy(DefaultCorsPolicyName, builder => { //App:CorsOrigins in appsettings.json can contain more than one address with splitted by comma. builder .WithOrigins("http://[domain].com","http://localhost:4200" // 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() ) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); })
-
0
did you also check appsettings.production.json and appsettings.Staging.json? I guess it's related with your environment settings. Make appsettings.production.json and appsettings.Staging.json same as appsettings.json.