title: ASP.NET Boilerplate CORS Problem outside localhost
body: <p>I created a project using the startup templates (<a href="https://aspnetboilerplate.com/Templates" rel="nofollow noreferrer">https://aspnetboilerplate.com/Templates</a>) using ASP.NET Core 2.x, .NET Core(Cross Platform), SPA(Angular), and multiple solutions configuration. I created the database and executed necessary migrations. I am now able to use the application via localhost:4200. But, when I wanted to connect from other devices in company network using mylocalip:4200; I got CORS error. </p>
  
  <p>I didn't change the template's code, but my ConfigureServices method:</p>
  
  <pre><code>public IServiceProvider ConfigureServices(IServiceCollection services)
  {
      // MVC
      services.AddMvc(
          options =&gt; options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName))
      );
  
      IdentityRegistrar.Register(services);
      AuthConfigurer.Configure(services, _appConfiguration);
  
      services.AddSignalR();
  
      // Configure CORS for angular2 UI
      services.AddCors(
          options =&gt; options.AddPolicy(
              _defaultCorsPolicyName,
              builder =&gt; builder
                  .WithOrigins(
                      // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                      _appConfiguration["App:CorsOrigins"]
                          .Split(",", StringSplitOptions.RemoveEmptyEntries)
                          .Select(o =&gt; o.RemovePostFix("/"))
                          .ToArray()
                  )
                  .AllowAnyHeader()
                  .AllowAnyMethod()
                  .AllowCredentials()
          )
      );
  
      // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
      services.AddSwaggerGen(options =&gt;
      {
          options.SwaggerDoc("v1", new Info { Title = "Example API", Version = "v1" });
          options.DocInclusionPredicate((docName, description) =&gt; true);
  
          // Define the BearerAuth scheme that's in use
          options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
          {
              Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
              Name = "Authorization",
              In = "header",
              Type = "apiKey"
          });
      });
  
      // Configure Abp and Dependency Injection
      return services.AddAbp&lt;ExampleWebHostModule&gt;(
          // Configure Log4Net logging
          options =&gt; options.IocManager.IocContainer.AddFacility&lt;LoggingFacility&gt;(
              f =&gt; f.UseAbpLog4Net().WithConfig("log4net.config")
          )
      );
  }
  </code></pre>
  
  <p>My Configure method:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      app.UseAbp(options =&gt; { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework.
  
      app.UseCors(_defaultCorsPolicyName); // Enable CORS!
  
      app.UseStaticFiles();
  
      app.UseAuthentication();
  
      app.UseAbpRequestLocalization();
  
  
      app.UseSignalR(routes =&gt;
      {
          routes.MapHub&lt;AbpCommonHub&gt;("/signalr");
      });
  
      app.UseMvc(routes =&gt;
      {
          routes.MapRoute(
              name: "defaultWithArea",
              template: "{area}/{controller=Home}/{action=Index}/{id?}");
  
          routes.MapRoute(
              name: "default",
              template: "{controller=Home}/{action=Index}/{id?}");
      });
  
      // Enable middleware to serve generated Swagger as a JSON endpoint
      app.UseSwagger();
      // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
      app.UseSwaggerUI(options =&gt;
      {
          options.SwaggerEndpoint(_appConfiguration["App:ServerRootAddress"].EnsureEndsWith('/') + "swagger/v1/swagger.json", "Example API V1");
          options.IndexStream = () =&gt; Assembly.GetExecutingAssembly()
              .GetManifestResourceStream("Example.Web.Host.wwwroot.swagger.ui.index.html");
      }); // URL: /swagger
  }
  </code></pre>
  
  <p>According to these methods the server should take the 3 URLs from appsettings.json file and allow CORS for them.</p>
  
  <pre><code>("CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081")
  </code></pre>
  
  <p>"<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>" in appsettings.json is my client app url that belongs to Angular application. I tried adding mylocalip:4200 to CorsOrigins list and tried changing withOrigins(...) method in AddCors(...) with allowAnyOrigin()(it should allow any machine to connect to the server), these changes didn't work, either.</p>
  
  <p><a href="https://i.stack.imgur.com/xvSqH.png" rel="nofollow noreferrer">Error seen from Chrome Browser</a></p>
  
  <p>Further related question: I searched the documentation, but I couldn't find it: what are ABP's best practices when deploying the application in production mode. Is there any recommended way to do this?</p>
  
  <p>Thanks in advance,</p>