Communication between ASP.NET and .NET Core projects

Question: How do I configure solution with a .NET Core application to use the same controllers, routes, and authentication handled by an ASP.NET application in the same solution?

Background: I have a project that is a single page application built with the ASP.NET Single Page Application template included in VS. The template creates a project using knockout as the SPA library. I am going to greatly expand the codebase of the application and we are going to move it to an Angular project.

I'd like to use the new Angular template that properly takes advantage of the Angular CLI as well as uses the more lightweight .NET Core. The problem is that I dont know how to take advantage of all the backend codebase currently maintained in the original ASP.NET application from the .NET Core project in the same solution.

I am able to develop the Angular application within the original ASP.NET application by creating a ClientApp directory and building a new Angular CLI application in that directory. I develop using the `ng build --watch` command which outputs static files on every save to a ClientDist directory. I can then serve up the rendered static assets from any given route by adding a few adjustments to my web.confg and calling the following in the associated controller:

public ActionResult Index()
            return new FilePathResult("/ClientDist/index.html", "text/html");

Open in new window

The major downside to this approach is:
1) I believe it muddles concerns of the codebase. An Angular CLI application is a very large undertaking that should be seperate from the rest of the backend codebase as much as possible.
2) (the real downside) I cant figure out how to debug my Typescript files in the browser. Normally when you develop an Angular CLI app you can set breakpoints in the compiled code thats then mapped to the original Typescript file. With this model I only have the compiled code. Its doable right now since its a small application, but it'll hamstring us latter.
Who is Participating?
Such issues exist not just with ASP.NET but other major webframeworks like Django (python) for example.

Angular is well suited for an SPA scenario but unfortunately and unlike AngularJS it has made integration with server frameworks much difficult. I read somewhere that the newer versions may address such shortcomings but until then we'll have to cope with it. The type of integration that you are attempting is painfully slow with ng building into the statics folder every time something changes because you'd want to serve from the Webserver and not ng serve.

Some things that may improve the integrated development process:

1. Extensive use of mockups to test the SPA without the backend can speedup test and development.
2. It maybe worthwhile to setup the SPA as a client to the server (a separate Visual Studio project, at least for as long as dev goes). This may require some CORS features to be added to the server app and running both the client and server on different URLs. However, unless your webapp is fully SPA or multi-SPA this may not work as seamlessly as desired.
axnst2Author Commented:
I think having the SPA client in a separate project in the same solution with CORS set up to communicate between the two during development is the most likely solution. Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.