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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.