Base solution for your next web application
Open Closed

Publishing ASP.NET Core and Angular (single solution) to IIS #9634


User avatar
0
bulutyonetim created

What is your product version? 9.0.1 What is your product type (Angular or MVC)? Angular (single solution) What is product framework type (.net framework or .net core)? ASP.NET CORE


Hi

Is there any step by step guide for publishing ASP.NET Core and Angular single solution to IIS? If not can guide me how to host API (.Net Core) and UI (Angular) on same site on iis? What about "ServerRootAddress": "https://localhost:44301/", "ClientRootAddress": "http://localhost:4200/" settings in appsetting.jso and etc...

Thanks.


6 Answer(s)
  • User Avatar
    0
    smry created

    https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Deployment-Angular-Publish-IIS

  • User Avatar
    0
    bulutyonetim created

    I asked for ASP.NET Core and Angular single solution not seprated.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    For single solution ServerRootAddress and ClientRootAddress will be the same. Unfortunately we don't have a document right now. If you publish your app on Windows, it should work out of the box.

    We will create a document as well, please follow https://github.com/aspnetzero/aspnet-zero-core/issues/3501.

    If you face any problems, please let us know.

  • User Avatar
    0
    bulutyonetim created

    Hi @ismcagdas,

    tnx

  • User Avatar
    0
    bulutyonetim created

    Hi,

    I tried these steps:

    1. Configure Web.Host\appsettings.Staging.json as you said with same value like this:

      {
        "ConnectionStrings": {
          "Default": "Server=localhost; Database=xxxDb; User=xxx; Password=xxx;"
        },
        "App": {
          "ServerRootAddress": "http://{TENANCY_NAME}.test.sitename.com/",
          "ClientRootAddress": "http://{TENANCY_NAME}.test.sitename.com/",
          "CorsOrigins": "http://test.sitename.com,http://*.test.sitename.com"
        }
      }
      
    2. Run dotnet publish --configuration Staging --output ../../Publish/SiteName /p:EnvironmentName=Staging

    3. Create IIS web site with these bindings test.sitename.com and *.test.sitename.com

    4. Copied all publish files to IIS site's physical path.

    5. Then tried to visit test.sitename.com, I get this erorr Oops! You're lost. We can not find the page you're looking for.

    6. Then tried to visit test.sitename.com/ui/login it loads api login pages. But i couldn't find a way to load ui.

    7. I Change config like this:

      {
        "ConnectionStrings": {
          "Default": "Server=localhost; Database=xxxDb; User=xxx; Password=xxx;"
        },
        "App": {
          "ServerRootAddress": "http://{TENANCY_NAME}.api.test.sitename.com/",
          "ClientRootAddress": "http://{TENANCY_NAME}.test.sitename.com/",
          "CorsOrigins": "http://test.sitename.com,http://*.test.sitename.com"
        }
      }
      

    but result was same.

    note: I can get things work with two IIS site one for UI and the other for api. But I think it shoud also work under one site.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bulutyonetim

    I suggest you to create a single solution using the same project name. In that project, you will see a custom middleware code in Startup.cs.

    This middleware redirects all not found request to index.html, so your Angular app will be runned in such cases. Place this code into your Statup.cs and also publish your Angular app and copy it's output to wwwroot folder of the published server side app.