Deploy and host .net core 2.0 and angular 6 app

2019-07-21 22:42发布

问题:

Intro:

Currently, I have two separate projects. One solution is for .NET core Web API 2.0 and another project is Angular 6 app.

I have a problem deploying this to my hosting provider ( asphostsportal ). It consists of one root folder httpdocs where when I publish my API I copy contents of publishing folder.

After transferring files via FTP I confirm that my API works by sending a request and getting the response.

Now I need to publish my angular project. The simplest way to do so is with ng build and I get some folder in dist.

Problem:

If I transfer contents of the folder inside dist to my root folder httpdocs on server It can't find any page but API still works.

If I transfer the whole folder inside httpdocs and set server Host setting to define document root to that folder:

It will find the index.html and show me my landing page. However then API won't work.

If I leave it as is and change the document root back to httpdocs ( where the API files are ) but push the index.html from httpdocs/website to httpdocs ( in this case I also edit index.html to point to website folder for resources etc ) in the hope it will find it ( server IIS setting )

It doesn't. After that my API starts working again. However, no landing page to be found.

Just FYI I do not have any extra startup.cs lines of code that have anything to do with static files nor did my publish command on API project create wwwroot folder ( like mentioned here)

Edit (Solution):

Okay, so I got it to work.

1) I added 2 lines of code in Configure method of Startup.cs in my API

  app.UseDefaultFiles();
  app.UseStaticFiles(); // For the wwwroot folder

Where according to MSDN "With UseDefaultFiles, requests to a folder search for: index.html"

2) I manually added wwwroot folder which for some reason was not generating upon publishing command for my API project. 3) In that folder I copied all contents of my dist/website angular publish files

And now it works, cheers!