ASP.NET MVC和Angularjs一起+的ASP.NET Web API [英] ASP.NET MVC and Angularjs together + ASP.NET Web API

查看:150
本文介绍了ASP.NET MVC和Angularjs一起+的ASP.NET Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用这些2世界的优缺点:


  • ASP.NET MVC和Angularjs在一起(不剃须刀,Angularjs会做的工作)。

  • AngularJS(前端)+的ASP.NET Web API(后端)。

我们正专注于SPA /迷你SPA与大量的服务器端业务规则和计算的中型/大型企业项目。林重点保障了。

的优点和缺点的意见会帮助我找到了我的脑袋里这个问题aswere:


  

难道是一个明智的决定使用的ASP.NET Web API(后端),ASP.NET
  MVC和Angularjs在一起吗?



解决方案

是的,明智的做法是把两者结合起来。显然,取决于具体的项目,你需要调整一些变量的最终解决方案。

什么你的建议实际上是我们在过去的2个或3个项目堆栈,这里的几个变种,并有根据具体的要求。我们使用的WebAPI + DurandalJS,+的WebAPI淘汰赛......所有的工作真的很好:) AngularJS似乎已经卡住的历史最久,国内逐渐流行到我们公司,以及在社会上的其余部分(这是一个决定对我来说因子)

当前技术堆栈。

  + ------------------------------------ +
                            |用法|
  + ------------------------- + ----------------------- ------------- +
  | AngularJS |该客户端应用程序的Web或移动|
  + ------------------------- + ----------------------- ------------- +
  |的WebAPI |为了您所有的数据访问需求|
  + ------------------------- + ----------------------- ------------- +
  | OAuth的&安培;承载令牌|对于认证和放大器;授权|
  + ------------------------- + ----------------------- ------------- +
  | SQL服务器和放大器; EF /任何|持久性|
  |任何其他NOSQL变种| &安培;存储|
  + ------------------------- + ----------------------- ------------- +
  |角UI / | |
  |角料|基本UI组件|
  + ------------------------- + ----------------------- ------------- +
  |武士刀|项目为收藏|
  | |在MS-Stack的支持OWIN |
  + ------------------------- + ----------------------- ------------- +
  | CORS |标准实施|
  | |跨域请求|
  + ------------------------- + ----------------------- ------------- +

好处:


  • Web应用程序可以移植到移动很容易(如果写在你意识到你可能会去移动这样的方式)


  • 您可以使用其他的服务很容易地访问API /应用程序,你应该选择...加上API的凉爽(相对于传统的访问机制)


  • AngularJS允许强大而结构化的客户端code(不,你不能做没有角,但在我的经验框架实施更好的做法,您应该坚持他们正确地)


  • 开始听起来像一个破纪录,但我们都知道,AngularJS是超级测试的


  • 您可以使用的<一个href=\"https://blog.mariusschulz.com/2015/02/22/bundling-and-minifying-an-angularjs-application-with-asp-net-mvc\"相对=nofollow>。净捆绑如果你害怕的的NodeJS之类咕噜/一饮而尽


    • 这并不是说你必须要害怕它(但熟悉>陌生)

    • 只要确保在客户端code被写在一个Minsafe方式


  • Visual Studio是实际上是相当冷静地发展,特别是与他们的新的重点放在开源的支持已晚。集成点阄<一个href=\"http://blogs.msdn.com/b/visualstudio/archive/2015/02/05/using-angularjs-in-visual-studio-2013.aspx\"相对=nofollow> AngularJS ,节点(你可能会在某个时候使用),显然ASP.Net MVC


缺点:

也。值得一读:


  1. <一个href=\"http://programmers.stackexchange.com/questions/23386/pros-and-cons-of-restful-architecture\">Pros和缺点RESTful架构


  2. 宁静的WebAPI VS常规控制器(A previous问题,我问,当它来设计/理解的WebAPI和放大器; REST设计)


I would like to know the advantages and disadvantages of using these 2 worlds:

  • ASP.NET MVC and Angularjs together(without razor, Angularjs will do the job).
  • AngularJS(front end) + ASP.NET Web API(back end).

We are focusing on SPA/Mini-SPA for a medium/large Enterprise project with a lot of server side business rules and calculations. Im focusing on security too.

The advantages and disadvantages opinions would help me to find the aswere for this question inside my head:

Would it be a wise decision to use ASP.NET Web API(backend), ASP.NET MVC and Angularjs together?

解决方案

Yes, it would be wise to combine the two. Obviously depending on the exact project, you need to tweak some of the variables in the final solution.

What you are suggesting has actually been our stack for the last 2 or 3 projects, with a few variants here and there based on specific requirements. We've used WebAPI + DurandalJS, WebAPI + Knockout... All work really well :) AngularJS seems to have stuck around the longest, gaining popularity internally to our company, as well as in the rest of the community (which is a deciding factor for me)

Current Tech Stack.

                            +------------------------------------+
                            |               Usage                |
  +-------------------------+------------------------------------+
  | AngularJS               | The client app web, or mobile      |
  +-------------------------+------------------------------------+    
  | WebAPI                  | For all your data access needs     |
  +-------------------------+------------------------------------+
  | OAuth & Bearer Tokens   | For Authentication & Authorization |
  +-------------------------+------------------------------------+
  | SQL Server & EF / any   |  Persistence                       |
  | any other noSQL variant |  & Storage                         |
  +-------------------------+------------------------------------+
  | Angular-UI /            |                                    |
  | Angular-Material        | Base UI components                 |
  +-------------------------+------------------------------------+
  | Katana                  | Collection of projects for         |
  |                         | supporting OWIN on MS-Stack        |
  +-------------------------+------------------------------------+
  | CORS                    | Standard for implementing          |
  |                         | cross domain requests              |
  +-------------------------+------------------------------------+

Benefits:

  • Web App can be ported to mobile quite easily (if written in such a way that you're aware that you might be going mobile)

  • You have an API that you can easily access using other services / apps should you choose to... plus API's are cool (compared to legacy access mechanisms)

  • AngularJS allows for powerful yet structured client side code (not that you cant do it without Angular, but in my experience the framework enforces better practices, should you adhere to them correctly)

  • Starting to sound like a broken record, but as we all know, AngularJS is super testable

  • You can make use of the .Net bundling if you're scared of NodeJS and things like grunt/gulp

    • Not that you have to be scared of it (but familiarity > unfamiliarity)
    • Just make sure the client side code gets written in a Minsafe way
  • Visual Studio is actually quite cool to develop in, specifically with their new focus on open source support of late. Lots of integration points for AngularJS, Node (which you'll probably use at some point), and obviously ASP.Net MVC

Cons:

  • If your not familiar with Angular there's a nice ol' learning curve

  • Possible duplication of validation

    • In order to reduce round trips/callbacks, it's obviously preferable to send through correct data on the first go. So in a few (or most) instances, we needed to duplicate some of the data level validations in JavaScript
  • Although it might not be applicable, and is a bit of a long shot... I've been at a client where they strictly want to use everything MS because opensource is "less secure", because people have access to the framework code... go figure. So make sure that they're open to using a SPA framework that's open source (this could apply to any other framework or tool) (and all that goes with it)

  • Duplication in security. You'll need to make sure to secure the API & the application. (As there is a disconnect between the two layers)

  • You'll need to learn how CORS works, and how to impliment it correctly as its likely that your API and web app will not be on the same domain/origin

Also. Worth taking a read:

  1. Pros And Cons Of Restful Architecture

  2. Restful WebAPI vs Regular Controllers (A previous question I asked when it came to designing / understanding WebAPI & REST designs)

这篇关于ASP.NET MVC和Angularjs一起+的ASP.NET Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆