Base solution for your next web application
Open Closed

Error in angular UI after deploying the site #5509


User avatar
0
kumaran created

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)
  • User Avatar
    0
    alper created
    Support Team

    as I see from your configuration, your both subdomains are the same "http://sandboxServer.xxxxxx.com", right?

  • User Avatar
    0
    kumaran created

    No, both are different.

    sandboxServer.domain.com sandboxClient.domain.com

  • User Avatar
    0
    ismcagdas created
    Support Team

    Could you check App_Data/Logs.txt file for error details.

  • User Avatar
    0
    kumaran created

    I do not have any app data folder.

  • User Avatar
    0
    ryancyq created
    Support Team

    <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

  • User Avatar
    0
    kumaran created

    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"

  • User Avatar
    0
    kumaran created

    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

  • User Avatar
    0
    kumaran created

    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" },

  • User Avatar
    0
    alper created
    Support Team

    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>

  • User Avatar
    0
    kumaran created

    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(); }); });

  • User Avatar
    0
    kumaran created

    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();
                    });
                });
    
  • User Avatar
    0
    kumaran created

    Can someone please help me. I am stuck here and not able to run my angular site after deploying. thanks

  • User Avatar
    0
    alper created
    Support Team

    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

  • User Avatar
    0
    kumaran created

    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();
                    });
                })
    
  • User Avatar
    0
    alper created
    Support Team

    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.