I've looked some time for a good explanation about the association between ASP.NET (MVC/WebAPI) as server-side and AngularJS as the client. But I'm still uncertain whether is it the correct way to implement a SPA with both technologies.
My idea is, to use ASP.NET as REST service. But I'm impressed about the Bundle in ASP.NET. To use it I need ASP.NET MVC and its Razor templates. Is that a good practice for building an application with angularjs as client?
I guess I only need MVC for authorization if the user is allowed to go on relevant pages. Or is there a better way with angular to find out the windows user? Because I need the account of the windows login user.
I hope anyone can help me to find out the right way.
My team has built an application in the past where we had 2 razor pages, the one was basically the external app (by external I mean non-logged in user) which was quite light weight and only handled signup, then the other acted as an internal shell for the rest of the app (once logged in).
I recently stumbled across a really cool bootstrap project that can help you construct a boilerplate app. My suggestion is just download this, and have a look through the boilerplate app to give you more clarity on its usage. (Then it's up to you if you want to use it or not, but it'll give you more clarity on solution construction)
Thus your final app would have one (or 2) MVC controller(s) that deliver your shell pages, and all other calls would be done via WebAPI endpoints. See rough example below:
..\Controllers\RootController.cs
..\Views\Root\Index.cshtml
..\WebAPI\SomethingController.cs
Tip: The easiest way I've found to construct projects like this is to use the Visual Studio's New Project Wizard. Select Web Project ->
MVC
, Make sure to SelectWebAPI
. This will ensure that App_Start has all the required routes & configs pre-generated.I assume you are using Angular 1.x. I don't see any constraints in using both razor and the template provided by angular, but generally you'd be better off in sticking with angular's template system. Here's some pointers:
Bundling and Minifying an AngularJS Application with ASP.NET MVC
Bundling and Minifying an AngularJS Application with ASP.NET MVC