title: Publish ASP.Net Core App on local IIS - Content not found
body: <p>I created a project in Visual Studio Code using following command:</p>
  <p><code>dotnet new angular --use-local-db</code></p>
  <p>Thereafter I updated angular from version 8 to 10 and finished the project. I tested using</p>
  <p><code>dotnet watch run</code></p>
  <p>All worked fine for me and I tried to publish it on my local IIS. Sadly I will not get it run. I tried different solutions found on several pages ended up using Visual Studio to publish the project on IIS. I used the following instructions, except Code First Migration because the necessary database already exists:
  <a href="https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis#create-the-publish-profile" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-to-iis#create-the-publish-profile</a></p>
  <p>The problem is that if I do so, Visual Studio will create an &quot;application&quot; called, let's say, &quot;myproject&quot;. When I then run &quot;Browse...&quot; on it I will get following errors in console:</p>
  <p><code>Failed to load resource: the server responded with a status of 404 (Not Found)    style. ... .css</code></p>
  <p><code>Failed to load resource: the server responded with a status of 404 (Not Found)    runtime-es2015. ... .css</code></p>
  <p><code>Failed to load resource: the server responded with a status of 404 (Not Found)    polyfills-es2015. ... .css</code></p>
  <p><code>Failed to load resource: the server responded with a status of 404 (Not Found)    main-es2015. ... .css</code></p>
  <p>The mentioned folders are on the mentioned directory ('ClientApp\dist'). Is there anything I missed to configure or set up?</p>
  <p>Any help would be appreciated.</p>
  <hr />
  <p>Edit after first reply:</p>
  <p>Startup.cs</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      ...
      services.AddSpaStaticFiles(configuration =&gt;
      {
          configuration.RootPath = &quot;ClientApp/dist&quot;;
      });
      ...
  }
  
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
      ...
      app.UseHttpsRedirection();
      app.UseStaticFiles();
      ...
      app.UseRouting();
      ...
      app.UseSpa(spa =&gt;
      {
          spa.Options.SourcePath = &quot;ClientApp&quot;;
  
          if (env.IsDevelopment())
          {
              spa.UseAngularCliServer(npmScript: &quot;start&quot;);
          }
      });
  }      
  </code></pre>
  <hr />
  <p>Edit after second reply:</p>
  <p>Here a some directories/paths. Hope the needed once are found here.</p>
  <p>Project Structur</p>
  <pre><code>[Root]
      ClientApp
          src
              app
                  [Angular Web App related files]
                  app.module.ts
                  ...
              main.js
              index.html
              styles.css
              polyfills.ts
              ...
          package.json
          angular.json
      [ASP.NET Core Web API Files]
      appsettings.json
      [Project].csproj
      Program.cs
      Startup.cs
  </code></pre>
  <p>IIS Files</p>
  <pre><code>wwwroot
      [Project]
          ClientApp
              dist
                  index.html
                  main. ... .js
                  polyfills. ... .js
                  runtime. ... .js
                  styles. ... .css
          [ASP.NET Core Web API Files]
  </code></pre>
  <p>How I call the project in browser:</p>
  <pre><code>localhost/[Project]
  </code></pre>
  <p>Paths shown when I press ctrl+U and try to access the files:</p>
  <pre><code>Requested URL: localhost:Port/main. ... .js
  Physical Path: ...\wwwroot\main. ... .js
  </code></pre>
  <hr />
  <p><strong>New Observation:</strong></p>
  <p>If I modify index.html of the angular client from</p>
  <pre><code> &lt;base href=&quot;/&quot; /&gt;
  </code></pre>
  <p>to</p>
  <pre><code> &lt;base href=&quot;/[projectname]/&quot; /&gt;
  </code></pre>
  <p>The page is loading in Prod on IIS but it fails in development mode.
  Also then in Prod on IIS it uses the url localhost/api/[controller] instead of working url localhost/[projectname]/api/[controller]. Last mentioned url I can access by entering it to the browser and it returns the data.</p>
  <p>If I then modifiy the service file for the controller from</p>
  <pre><code>...
  return this.http.get('/api/[controller]')
  ...
  </code></pre>
  <p>to</p>
  <pre><code>...
  return this.http.get('[projectname]/api/[controller]')
  ...
  </code></pre>
  <p>it tries to access path: localhost/[projectname]/[projectname]/api/[controller]</p>
  <p>Any Idea what I missconfigured or where I need to change configuration so that the project works in Prod and Dev Mode?</p>
  <p>Any help would be appreciated.</p>