I am currently at the beginning process of starting a new application and am quite new to MVC and Angular. So far i have created a custom authorize attribute using asp.net MVC, this enables me to use the [Authorize] tag. Is it possible to use with an AngularJS front-end?
Any resources that will point me in the right directions would be appreciated.
AngularJs is really good for single-page-applicaitons (SPA). So just separate your front-end and back-end layers. Use Angular to implement all the views and front-end stuff. Use ASP.NET WebAPI to expose REST API for front-end (and maybe mobile) app.
A few useful links:
Angular Routing module
ASP.NET WebAPI Bearer token authorization with AngularJs
Routing in SPA with AngularJs
The answer is YES! So you can still benefit from ASP.NET MVC features like authentication and authorization etc. and still use AngularJS on the client.
I actually had the same question and after a bit of research I discovered the following.
It's true we should embrace SPAs (single page apps) but at the same time we should not just discard mature server-side frameworks such ASP.NET MVC. You can simply have a hybrid web app or mini SPA as we also call them. These web applications use normal ASP.NET MVC routing to show views and then, once the view loads you can leave all the responsabilities to AngularJS. Miguel Castro uses the term SPA silos. Plus you can benefit from AngularJS' routing as well. Miguel Castro also explains how to use them both together to get the best of server and client side. I really suggest seeing his presentation (link below).
In that way you can still benefit from ASP.NET MVC great features like Authentication, Authorization and others but still have AngularJS run your views.
I got this answer on the following locations that you definitely should check out:
Miguel Castro: AngularJS for ASP.NET MVC Developers
PluralSight - Cooper, Eames: AngularJS for .NET Developers
StackOverflow: Mixing Angular and ASP.NET MVC/Web api?
StackOverflow: ASP.NET MVC and Angular JS tipping point
Related
I am a beginner to angular4 wanted to integrate angular with asp.net MVC,
Should I use the only Angular to develop web Application or with MVC ?
AngularJS is a Client Side web (for browser) development framework, and it has nothing to do with the server-side stuff (eg. database related operations or managing user session).
You can use ASP.NET MVC with angular, but it's a good practice to use WEB API, because the View part from MVC will be taking care by the angular framework.
It shouldn't be a problem. You'll need to add a json api to your .net app but people do it all the time. As with everything, right tools for the right job though.
I want to know if Angular JS can be used with ASP.NET MVC architecture in any way? I have tried searching on Google, but can't figure out if Angular JS is usable in .cshtml page of ASP.NET MVC and is it the good idea to use it?
you can definitely use AngularJs with Asp.Net MVC as it is a client side framework which entirely runs in the browser. It doesn't depend on any of the Asp.Net features as such. There are lot of samples available online. Here is a channel 9 video which guides you through
From the official ASP.net pages: Hands On Lab: Build a Single Page Application (SPA) with ASP.NET Web API and Angular.js
The fact that is uses WebAPI shouldn't really matter here, as that's a detail matter of implementation. AngularJS works fine on top of either.
First hit on google...
If you looking to achieve CRUD in your application I recommend this post as a guide to follow. Even though this uses WEB API, its still a good way of getting to grips with angularjs.
Hope this helps.
CRUD with SPA, ASP.NET Web API and Angular.js
For a new SPA Web App which will initially have very little user interaction and incrementally will have new features which will require lot of user interaction. This app is targeted for mobile devices. I am using this weird combination of technologies.
AngularJS + jQuery Mobile - for Client Side - MVC framework + SPA framework.
ASP.NET MVC - Server side MVC Framework - which seems unnecessary.
WCF REST Services (from 3rd party) - Do not have any control here, just consuming it. These services returns JSON data. All business logic resides here. Application do not have any feature outside of this.
Once application loaded at client side all service calls will happen from AngularJS to REST Services.
The main role of ASP.NET MVC, is just initial request load only. Even user session is handled between AngularJS and REST services.
But I foreseen eventually application will be complex to handle all the stuff at client side. So looking to push some complex processing which is easy and efficient to get done using ASP.NET MVC and .NET Sandbox. I cannot ask REST Service to do this because as i mentioned it is 3rd party.
In dilemma,
1. Should i maintain user session on server side as well?
2. How can i utilize ASP.NET MVC best possible way?
Thanks for any suggestions.
Your dilemma is justified and valid. When I go with angularJs, my big question is , do i need to csthml file or shall i use the html file.
I always go with cshtml, hoping that in future there may be scenario where i may have to leverage the server side capabilities of the mvc.
Currently I am working on the same combination of technologies stated above and with modularity of arranging js codes(angular controllers) i don't see any issues. I am bit curious on what complexities you would be adding to the contoller as you have stated that all your business logic is done by the third partly controller.
If you are looking for security aspect, I would suggest you to write a custom actionfilter which uses httpmodule to do the custom security handling.
With MVC , sessions should be a BIG NO . At lease in my organisation it so.
I have a web site I'd like to switch to ADFS/WIF (Windows Identity Foundation).
The web site has some ASP.NET MVC and other regular (WebForms) ASP.NET.
I've seen examples for MVC and examples for WebForms, but how can I have a blend of both flavors of ASP.NET living side by side in the same web site (same domain) which still supporting WIF for SSO in each?
WIF doesn't care whether the app. is ASP.NET or ASP MVC. Just bind your app. to ADFS using FedUtil and it will work. FedUtil just changes the web.config.
You'll lose your current authentication pages (in the sense they won't be invoked) but the rest of the app. is untouched and will work as per normal.
If your app. is not currently claims-based, you'll have to make changes to consume the claims.
I have a classic asp project and a teammate created a new functionality, but it's in asp.net mvc. I also know how to work with mvc, but I never used classic asp and mvc together.
For example, is it possible, in this classic asp project, to have a link that will redirect to a mvc page on the same project?
Thanks!!
Yes, you can have a link point to any other page you'd like regardless of technology. Likewise for a redirect. To redirect in classic ASP, use Response.Redirect
Absolutely, the pages (and that term is used lightly in the MVC side of things) can link between each other without any problems. Now, any built-in authentication or session management or anything like that will be considerably more challenging, but if all the sites need to do is link to each other then they can do this like any other two websites. The ASP pages can host manually-crafted (vs. HtmlHelper-crafted) links to the MVC actions, and can host forms that post values to the MVC actions (provided the field names line up properly).
There's nothing inherently special about the MVC actions. They're just handling HTTP GET/POST requests like anything else.