简体   繁体   English

ASP.NET 和 ASP.NET MVC 有什么区别?

[英]What is the difference between ASP.NET and ASP.NET MVC?

I'm a complete beginner when it comes to ASP.NET but I want to learn it in order to build a web application that eventually will communicate with a cloud hosted SQL server.对于 ASP.NET,我是一个完整的初学者,但我想学习它以构建一个最终将与云托管的 SQL 服务器通信的 Web 应用程序。 However, I cannot find any information that outlines the difference between ASP.NET web application and ASP.NET MVC2 web application (in visual studio 2010) so I'm not sure where to start.但是,我找不到任何概述 ASP.NET Web 应用程序和 ASP.NET MVC2 Web 应用程序(在 Visual Studio 2010 中)之间区别的信息,所以我不确定从哪里开始。 Can anyone give me a simple explanation/outline so I can decide on a tutorial to follow?谁能给我一个简单的解释/大纲,以便我可以决定要遵循的教程?

Thanks谢谢

ASP.NET is a web platform. ASP.NET 是一个网络平台。 It provides a layer that sits on top of IIS (the web server) which facilitates the creation of web applications and web services.它提供了一个位于 IIS(Web 服务器)之上的层,便于创建 Web 应用程序和 Web 服务。 ASP.NET MVC is a framework specifically for building web applications. ASP.NET MVC 是一个专门用于构建 Web 应用程序的框架。 It sits ontop of ASP.NET and uses APIs provided by ASP.NET.它位于 ASP.NET 之上并使用 ASP.NET 提供的 API。 ASP.NET Web Forms is another framework specifically for building web applications, and the new ASP.NET Web API is a platform for building web services. ASP.NET Web Forms 是另一个专门用于构建 Web 应用程序的框架,而新的 ASP.NET Web API 是用于构建 Web 服务的平台。

ASP.NET, at its most basic level, provides a means for you to provide general HTML markup combined with server side "controls" within the event-driven programming model that can be leveraged with VB, C#, and so on. ASP.NET 在最基本的层面上为您提供了一种方法,可以在可与 VB、C# 等一起使用的事件驱动编程模型中提供与服务器端“控件”相结合的通用 HTML 标记。 You define the page(s) of a site, drop in the controls, and provide the programmatic plumbing to make it all work.您定义站点的页面,放入控件,并提供程序化管道以使其全部工作。

ASP.NET MVC is an application framework based on the Model-View-Controller architectural pattern. ASP.NET MVC 是一个基于模型-视图-控制器架构模式的应用程序框架。 This is what might be considered a "canned" framework for a specific way of implementing a web site, with a page acting as the "controller" and dispatching requests to the appropriate pages in the application.这可能被认为是用于实现网站的特定方式的“固定”框架,页面充当“控制器”并将请求分派到应用程序中的适当页面。 The idea is to "partition" the various elements of the application, eg business rules, presentation rules, and so on.这个想法是“划分”应用程序的各种元素,例如业务规则、表示规则等。

Think of the former as the "blank slate" for implementing a site architecture you've designed more or less from the ground up.将前者视为实现您或多或少从头开始设计的站点架构的“白板”。 MVC provides a mechanism for designing a site around a pre-determined "pattern" of application access, if that makes sense. MVC 提供了一种机制,用于围绕预先确定的应用程序访问“模式”设计站点(如果有道理的话)。 There's more technical detail to it than that, to be sure, but that's the nickel tour for the purposes of the question.可以肯定的是,它有更多的技术细节,但就问题而言,这是镍之旅。

Good luck!祝你好运!

ASP.NET MVC2 web application is based on MVC pattern in order to facilitate unit test, without mocking pipeline asp.net, because it's very difficult. ASP.NET MVC2 Web 应用程序基于MVC 模式以方便单元测试,没有模拟管道asp.net,因为它非常困难。 you don't have code on Code Behind in order to separate your code graphic and your code functional.您没有代码隐藏代码以将您的代码图形和您的代码功能分开。

With MVC your application become independent from view.使用 MVC,您的应用程序将独立于视图。 you can replace easily technology of creating view.您可以轻松替换创建视图的技术。

Read this article it's very interesting : http://msdn.microsoft.com/en-us/magazine/dd942833.aspx阅读这篇文章很有趣: http : //msdn.microsoft.com/en-us/magazine/dd942833.aspx

If you have VS10 make a small ASP.NET (webforms) application and a small ASP.NET MVC 2 application, and examine the differences between them.如果您使用 VS10 制作一个小型 ASP.NET (webforms) 应用程序和一个小型 ASP.NET MVC 2 应用程序,并检查它们之间的差异。 It's a great way to learn.这是一个很好的学习方式。

Like ASP.Net web forms, ASP.Net MVC is development model to build web application in Microsoft .net framework.与 ASP.Net Web 表单一样,ASP.Net MVC 是在 Microsoft .net 框架中构建 Web 应用程序的开发模型。 The major difference between them are ASP.net MVC is based on the MVC architecture.它们之间的主要区别是 ASP.net MVC 基于 MVC 架构。 Where we have 3 independent tiers – Model, View Controllers which interact which each other to render HTML output.我们有 3 个独立的层——模型、视图控制器,它们相互交互以呈现 HTML 输出。

Major differences主要区别

  1. Web forms is mainly has an event driven model. Web 表单主要有一个事件驱动模型。 Where we have page level events(Page_load, pre render, page_init etc) and control level events.我们有页面级事件(Page_load、pre render、page_init 等)和控制级事件。 Which is not the case for MVC. MVC 的情况并非如此。 The request life cycle is comparatively complex.(why complex because, the request has to goes through all the events before rendering the HTML output )请求生命周期比较复杂。(为什么复杂是因为,请求在呈现 HTML 输出之前必须经历所有事件)

  2. Web forms is basically has an aspx page which contains UI controls and a code behind file. Web 表单基本上有一个包含 UI 控件和代码隐藏文件的 aspx 页面。 All the page level events and control level events are handled here.所有页面级事件和控制级事件都在这里处理。 In MVC the View, Model , controller can exist independently (gives clear separation of concern)在MVC中,视图、模型、控制器可以独立存在(给出明确的关注点分离)

  3. The SOC makes it easier for development as we can have separate developers for View(design html) and controller (implement business logic) SOC 使开发更容易,因为我们可以为 View(设计 html)和控制器(实现业务逻辑)提供单独的开发人员

  4. Because of this tight coupling nature, web forms are not suitable for unit tests.由于这种紧密耦合的性质,Web 表单不适合单元测试。 In MVC we can write unit tests at both controller level, action method levels.在 MVC 中,我们可以在控制器级别和操作方法级别编写单元测试。 Here we can mock the data to be passed to view and do assert the result from the action method for their different properties like view name, model properties, null check etc在这里,我们可以模拟要传递给视图的数据,并为它们的不同属性(如视图名称、模型属性、空检查等)断言来自 action 方法的结果

  5. In web forms we have state full behavior.在 Web 表单中,我们有状态完整的行为。 The server controls in ASPX page uses view state to retain their state during request response cycle. ASPX 页面中的服务器控件使用视图状态在请求响应周期中保持它们的状态。 Since this view states are stored as hidden controls inside the page itself, and they are sent during request and response cycle, it makes them more heavy.由于此视图状态作为隐藏控件存储在页面本身内部,并且它们在请求和响应周期中发送,因此它们更重。 Absence of view state and state less nature of MVC make it more light weight. MVC 没有视图状态和状态较少的特性使其重量更轻。 Hence they are much more faster in request lifecycle.因此,它们在请求生命周期中要快得多。

ASP.NET is a web platform. ASP.NET 是一个网络平台。 It provides a layer that sits on top of the web server which facilitates the creation of web applications and web services.它提供了一个位于 Web 服务器之上的层,便于创建 Web 应用程序和 Web 服务。 ASP.NET is a framework specifically for building web applications. ASP.NET 是一个专门用于构建 Web 应用程序的框架。 It sits of ASP.NET and uses APIs provided by ASP.NET.它位于 ASP.NET 并使用 ASP.NET 提供的 API。 ASP.NET Web Forms is another framework specifically for building web applications, and the new ASP.NET Web API is a platform for building web services ASP.NET Web Forms 是另一个专门用于构建 Web 应用程序的框架,新的 ASP.NET Web API 是构建 Web 服务的平台

ASP.NET is a 2 tier application in which no separate section for the database and MVC is a 3 tier application in which view and logic is kept separate. ASP.NET 是一个 2 层应用程序,其中没有单独的数据库部分,MVC 是一个 3 层应用程序,其中视图和逻辑保持分离。 In ASP.NET for each .aspx form one URL is generated, but in MVC the url's are generated based on the controller and by the router configuration.在 ASP.NET 中,每个.aspx表单都会生成一个 URL,但在 MVC 中,URL 是基于控制器和路由器配置生成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM