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

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

问题描述

我想知道使用这两个世界的优缺点:

  • ASP.NET MVC 和 Angularjs 一起使用(无需剃刀,Angularjs 即可完成工作).
  • AngularJS(前端)+ ASP.NET Web API(后端).

我们专注于 SPA/Mini-SPA,用于具有大量服务器端业务规则和计算的中/大型企业项目.我也很注重安全.

利弊意见将帮助我在脑海中找到这个问题的答案:

<块引用>

使用 ASP.NET Web API(后端)、ASP.NET 是否是明智的决定MVC 和 Angularjs 在一起?

解决方案

是的,将两者结合起来是明智之举.显然,根据具体的项目,您需要调整最终解决方案中的一些变量.

您所建议的实际上是我们过去 2 或 3 个项目的堆栈,根据特定要求,这里和那里有一些变体.我们已经使用了 WebAPI + DurandalJS、WebAPI + Knockout ......所有工作都非常好:) AngularJS 似乎坚持了最久的时间,在我们公司内部以及社区的其他成员中越来越受欢迎(这是一个决定性的我的因素)

当前的技术栈.

 +------------------------------------+|用法 |+---------------+---------------------------+|AngularJS |客户端应用程序 Web 或移动 |+---------------+---------------------------+|网络API |满足您所有的数据访问需求 |+---------------+---------------------------+|OAuth &不记名令牌 |用于身份验证和授权 |+---------------+---------------------------+|SQL Server &英孚/任何|坚持 ||任何其他 noSQL 变体 |&存储 |+---------------+---------------------------+|Angular-UI/|||角材料 |基础 UI 组件 |+---------------+---------------------------+|武士刀 |项目集合 |||在 MS-Stack 上支持 OWIN |+---------------+---------------------------+|CORS |实施标准|||跨域请求|+---------------+---------------------------+

优点:

  • Web 应用程序可以很容易地移植到移动设备上(如果编写的方式让您意识到自己可能会转向移动设备)

  • 如果您选择使用其他服务/应用程序,您可以轻松访问 API ......而且 API 很酷(与传统访问机制相比)

  • AngularJS 允许使用功能强大且结构化的客户端代码(并不是说没有 Angular 就无法实现,但根据我的经验,如果您正确遵守,该框架会强制执行更好的做法)

  • 听起来像是破唱片,但众所周知,AngularJS 是超级可测试的

  • 您可以使用 .Net 捆绑 如果你害怕 NodeJS 和 grunt/gulp 之类的东西

    • 并不是说你必须害怕它(但熟悉 > 不熟悉)
    • 只需确保以 Minsafe 方式编写客户端代码
  • Visual Studio 实际上非常适合开发,特别是最近他们对开源支持的新关注.AngularJS节点(您可能会在某个时候使用),显然是 ASP.Net MVC

缺点:

  • 如果您不熟悉 Angular,这里有一个不错的学习曲线

  • 可能的重复验证

    • 为了减少往返/回调,显然最好在第一次发送时发送正确的数据.因此,在少数(或大多数)情况下,我们需要在 JavaScript 中复制一些数据级验证
  • 虽然它可能不适用,而且有点远……我去过一个客户,他们严格想要使用 MS 的所有东西,因为开源不太安全",因为人们有访问框架代码...去图.因此,请确保他们愿意使用开源的 SPA 框架(这可以适用于任何其他框架或工具)(以及与之相关的所有内容)

  • 安全重复.您需要确保保护 API &应用程序.(因为两层之间存在脱节)

  • 您需要了解 CORS 的工作原理,以及如何正确实施它,因为您的 API 和 Web 应用程序可能不在同一域/来源

还有.值得一读:

  1. Restful 架构的优缺点

  2. Restful WebAPI 与常规控制器(我之前在设计时问过的一个问题)/了解 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天全站免登陆