Home:ALL Converter>Self host asp core - Angular 2 site with OWIN as console app

Self host asp core - Angular 2 site with OWIN as console app

Ask Time:2017-11-23T07:53:53         Author:james Makinde

Json Formatter

I have built an Angular project with ASP net core 2 and I have been trying to host it in OWIN to no avail. I used VS publish to generate the files to publish which works fine when run in IIS express directly from Visual Studio.

This is the file structure for the publish folders:

MainDirectory
    wwwroot
       dist
       favicon

I have setup a publish project in .NET (Visual Studio) and have the following in my startup.cs class but when I browse to the url after starting the service, there is nothing in the page: I used this code below.

const string rootFolder = "C:\\src\\StartupService\\maindirectory";
            var fileSystem = new PhysicalFileSystem(rootFolder);
            var options = new FileServerOptions
            {
                EnableDefaultFiles = true,
                FileSystem = fileSystem
            };

            app.UseFileServer(options);

I want to mention that I tested the OWIN self host server with the app.UseWelcome() page in C# and it was fine but it won't serve my Angular site. Just to mentioned that I don't see any html files in the publish folder anywhere, just DLLs, JSON files and web.config, so I don't know if that's a problem.

I also tried this code, but it didn't work too.

var physicalFileSystem = new PhysicalFileSystem("C:\\src\\StartupService\\maindirectory");
            var options = new FileServerOptions
            {
                EnableDefaultFiles = true,
                FileSystem = physicalFileSystem,
                StaticFileOptions =
                {
                    FileSystem = physicalFileSystem,
                    ServeUnknownFileTypes = true
                },
                // DefaultFilesOptions = {DefaultFileNames = new[] {"index.html"}}
            };
            app.UseFileServer(options);

Any idea how to self host an Angular 2 created with VS2017 in OWIN?

Author:james Makinde,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47445580/self-host-asp-core-angular-2-site-with-owin-as-console-app
yy