ASP.Net MVC与Classic ASP(不是ASP.Net - 原始ASP)有何不同

时间:2022-05-21 01:38:20

I'm trying to get a high-level understanding of ASP.Net MVC, and it has started to occur to me that it looks a lot like the original ASP script. Back in the day, we were organizing our "model"/business logic code into VBScript classes, or into VB COM components.

我试图对ASP.Net MVC有一个高层次的理解,它开始发生在我看来它看起来很像原始的ASP脚本。在当天,我们将“模型”/业务逻辑代码组织到VBScript类或VB COM组件中。

Of course, now we have the additional power of c# and the .net framework classes. Besides the high-level oo and other capabilities in c# and .Net, what are the other major differences between the original ASP and ASP.Net MVC?

当然,现在我们拥有c#和.net框架类的额外功能。除了c#和.Net中的高级oo和其他功能外,原始ASP和ASP.Net MVC之间的其他主要区别是什么?

4 个解决方案

#1


12  

There are three main differences: URL mapping, separation of logic from presentation, and strong typing.

主要区别有三个:URL映射,逻辑与表示的分离以及强类型。

URL Mapping

With classic ASP there is a smooth transition from writing HTML pages to writing HTML pages with dynamic content. As with static HTML files, each URL has a direct mapping to a file in the filesystem. The same thing is more or less true of ASP.NET, for what it's worth.

使用经典ASP,可以从编写HTML页面到编写具有动态内容的HTML页面顺利过渡。与静态HTML文件一样,每个URL都直接映射到文件系统中的文件。同样的事情或多或少都与ASP.NET有关,因为它的价值。

In ASP.NET MVC, each "family" of URLs maps to a Controller object (stored in the /Controllers directory, by default), where each member of the family calls a method when accessed. At the end of each method (typically), you tell it to render a particular view (stored in a folder named after the controller in the /Views directory), which is a lot like a classic ASP page with all of the logic separated out.

在ASP.NET MVC中,URL的每个“族”映射到Controller对象(默认情况下存储在/ Controllers目录中),其中该族的每个成员在访问时调用方法。在每个方法的末尾(通常),你告诉它渲染一个特定的视图(存储在/ Views目录中以控制器命名的文件夹中),这很像一个经典的ASP页面,所有逻辑都被分离出来。

This gives you logical and SEO-friendly URLs and groups related functionality together.

这为您提供了逻辑和SEO友好的URL和组相关的功能。

Separation of Logic from Presentation

In classic ASP it's common to find pages where a bit of HTML is included at the top, and then a database connection is opened and some things are read from the database while being output to the user, and then some more html, and then another database statement, and so on.

在经典的ASP中,通常会找到顶部包含一些HTML的页面,然后打开数据库连接,并在输出给用户时从数据库中读取一些内容,然后再输出一些html,然后是另一个数据库语句,等等。

In ASP.NET MVC, your business logic (e.g. validation) goes in the model layer (you can choose from one of several dozen, but popular choices are LINQ-to-SQL and LINQ-to-Entity-Framework), your human interface logic goes in the controller (e.g. populating a State/Province menu based on the Country selection), and your presentation (the actual HTML you can hand to a designer to edit) goes in the view.

在ASP.NET MVC中,您的业务逻辑(例如验证)进入模型层(您可以选择几十种,但流行的选择是LINQ-to-SQL和LINQ-to-Entity-Framework),您的人机界面逻辑进入控制器(例如,根据国家/地区选择填充州/省菜单),您的演示文稿(您可以交给设计人员编辑的实际HTML)进入视图。

Aside from keeping things organized, this helps a great deal with being able to write automated tests for things. You can send a mocked-up object to your view and make sure it looks good, you can send bad data to your model and make sure it complains, and you can make sure that the object your controller sends out to your view is consistent with what it reads from the model.

除了保持组织有序之外,这还有助于为事物编写自动化测试。您可以将一个模拟对象发送到您的视图,并确保它看起来不错,您可以将错误数据发送到您的模型并确保它抱怨,并且您可以确保控制器发送到您的视图的对象与您的视图一致它从模型中读取的内容。

Strong Typing and Compilation

ASP.NET is strongly typed and compiled. This is a double-edged sword. On the one hand, it will catch a lot of stupid programmer mistakes at compile time. On the other hand it, that means you're left with "infinity minus one" possible errors in your code (unit testing can make it infinity minus some larger number). Also, you'll have to do things like:

ASP.NET是强类型和编译的。这是一把双刃剑。一方面,它会在编译时捕获很多愚蠢的程序员错误。另一方面,它意味着您的代码中存在“无穷大减1”可能的错误(单元测试可以使其无穷大减去更大的数字)。此外,你必须做的事情如下:

if (MyArray.Length > 0)

rather than

if (MyArray.Length)

But IMHO that's a small price to pay for the speed and sanity-checking you get from strong typing.

但恕我直言,这是一个很小的代价来支付你从强打字得到的速度和理智检查。

The bigger downside to compiled languages in a big framework is that deployment becomes much more of a production than it is with something like Classic ASP. You can't just copy a couple of files to the web server to update your app. You typically have to take the webserver down (hopefully you have a redundant pair) and recompile, which can take minutes.

在一个大框架中编译语言的更大缺点是,部署变得比使用Classic ASP更具生产力。您不能只是将几个文件复制到Web服务器以更新您的应用程序。您通常必须关闭Web服务器(希望您有一个冗余对)并重新编译,这可能需要几分钟。

#2


2  

ASP.NET MVC has a lot of plumbing infrastructure: for example, the routing engine which automatically invokes the right controller and action and can extract bits from the URL to pass as action arguments; or the convention-based location of views. It also provides more structure for passing data from the controller into the view (the ViewData object).

ASP.NET MVC有很多管道基础设施:例如,路由引擎自动调用正确的控制器和动作,并可以从URL中提取位作为动作参数传递;或基于会议的观点位置。它还提供了更多结构,用于将数据从控制器传递到视图(ViewData对象)。

Also, crucially, MVC supports view engines. You can write raw HTML with helpers in it, but you can also use view engines like Web Forms, Spark, NHaml, etc. which allow you to write more concise view code, create reusable components (e.g. Web Forms controls), etc. This wasn't possible in ASP Classic.

此外,至关重要的是,MVC支持视图引擎。您可以在其中编写带有帮助程序的原始HTML,但您也可以使用Web窗体,Spark,NHaml等视图引擎,它们允许您编写更简洁的视图代码,创建可重用的组件(例如Web窗体控件)等。在ASP Classic中是不可能的。

#3


0  

Classic ASP used VBScript, which does not have classes. It's not object-oriented at all.

经典ASP使用的是VBScript,它没有类。它根本不是面向对象的。

#4


0  

Very often with different technologies we can achieve the same final result. To create simple sites is almost irrelevant to the choice of technology. But when you want to make a large complex site the presence or absence of a framework that allows to optimize the code, keep well organized and efficiently divide may play a role crucial and greatly reduce the work.

通常使用不同的技术,我们可以获得相同的最终结果。创建简单网站几乎与技术选择无关。但是当你想要建立一个大型复杂站点时,是否存在允许优化代码的框架,保持良好的组织和有效的划分可能起到至关重要的作用,并大大减少工作量。

ASP Classic does not achieve the same results reached by asp net mvc.

ASP Classic没有达到asp net mvc达到的相同结果。

If we omit the obvious differences between c # vb script I would say that the difference main is that you can keep your code better organized.

如果我们省略c#vb脚本之间明显的差异,我会说主要的不同之处在于您可以更好地组织代码。

As with classic ASP is very easy to make "spaghetti code and, with asp mvc, on the contrary, it is very easy to keep everything tidy and separate the code business logic from display.

与经典的ASP一样,很容易制作“意大利面条代码,相反,使用asp mvc,很容易保持一切整洁,并将代码业务逻辑与显示分开。

Not only that.

不仅。

Asp Net Mvc seamlessly integrates with technologies such as that EntityFramework allow a further breakdown and organization of the code.

Asp Net Mvc与EntityFramework等技术无缝集成,允许进一步细分和组织代码。

#1


12  

There are three main differences: URL mapping, separation of logic from presentation, and strong typing.

主要区别有三个:URL映射,逻辑与表示的分离以及强类型。

URL Mapping

With classic ASP there is a smooth transition from writing HTML pages to writing HTML pages with dynamic content. As with static HTML files, each URL has a direct mapping to a file in the filesystem. The same thing is more or less true of ASP.NET, for what it's worth.

使用经典ASP,可以从编写HTML页面到编写具有动态内容的HTML页面顺利过渡。与静态HTML文件一样,每个URL都直接映射到文件系统中的文件。同样的事情或多或少都与ASP.NET有关,因为它的价值。

In ASP.NET MVC, each "family" of URLs maps to a Controller object (stored in the /Controllers directory, by default), where each member of the family calls a method when accessed. At the end of each method (typically), you tell it to render a particular view (stored in a folder named after the controller in the /Views directory), which is a lot like a classic ASP page with all of the logic separated out.

在ASP.NET MVC中,URL的每个“族”映射到Controller对象(默认情况下存储在/ Controllers目录中),其中该族的每个成员在访问时调用方法。在每个方法的末尾(通常),你告诉它渲染一个特定的视图(存储在/ Views目录中以控制器命名的文件夹中),这很像一个经典的ASP页面,所有逻辑都被分离出来。

This gives you logical and SEO-friendly URLs and groups related functionality together.

这为您提供了逻辑和SEO友好的URL和组相关的功能。

Separation of Logic from Presentation

In classic ASP it's common to find pages where a bit of HTML is included at the top, and then a database connection is opened and some things are read from the database while being output to the user, and then some more html, and then another database statement, and so on.

在经典的ASP中,通常会找到顶部包含一些HTML的页面,然后打开数据库连接,并在输出给用户时从数据库中读取一些内容,然后再输出一些html,然后是另一个数据库语句,等等。

In ASP.NET MVC, your business logic (e.g. validation) goes in the model layer (you can choose from one of several dozen, but popular choices are LINQ-to-SQL and LINQ-to-Entity-Framework), your human interface logic goes in the controller (e.g. populating a State/Province menu based on the Country selection), and your presentation (the actual HTML you can hand to a designer to edit) goes in the view.

在ASP.NET MVC中,您的业务逻辑(例如验证)进入模型层(您可以选择几十种,但流行的选择是LINQ-to-SQL和LINQ-to-Entity-Framework),您的人机界面逻辑进入控制器(例如,根据国家/地区选择填充州/省菜单),您的演示文稿(您可以交给设计人员编辑的实际HTML)进入视图。

Aside from keeping things organized, this helps a great deal with being able to write automated tests for things. You can send a mocked-up object to your view and make sure it looks good, you can send bad data to your model and make sure it complains, and you can make sure that the object your controller sends out to your view is consistent with what it reads from the model.

除了保持组织有序之外,这还有助于为事物编写自动化测试。您可以将一个模拟对象发送到您的视图,并确保它看起来不错,您可以将错误数据发送到您的模型并确保它抱怨,并且您可以确保控制器发送到您的视图的对象与您的视图一致它从模型中读取的内容。

Strong Typing and Compilation

ASP.NET is strongly typed and compiled. This is a double-edged sword. On the one hand, it will catch a lot of stupid programmer mistakes at compile time. On the other hand it, that means you're left with "infinity minus one" possible errors in your code (unit testing can make it infinity minus some larger number). Also, you'll have to do things like:

ASP.NET是强类型和编译的。这是一把双刃剑。一方面,它会在编译时捕获很多愚蠢的程序员错误。另一方面,它意味着您的代码中存在“无穷大减1”可能的错误(单元测试可以使其无穷大减去更大的数字)。此外,你必须做的事情如下:

if (MyArray.Length > 0)

rather than

if (MyArray.Length)

But IMHO that's a small price to pay for the speed and sanity-checking you get from strong typing.

但恕我直言,这是一个很小的代价来支付你从强打字得到的速度和理智检查。

The bigger downside to compiled languages in a big framework is that deployment becomes much more of a production than it is with something like Classic ASP. You can't just copy a couple of files to the web server to update your app. You typically have to take the webserver down (hopefully you have a redundant pair) and recompile, which can take minutes.

在一个大框架中编译语言的更大缺点是,部署变得比使用Classic ASP更具生产力。您不能只是将几个文件复制到Web服务器以更新您的应用程序。您通常必须关闭Web服务器(希望您有一个冗余对)并重新编译,这可能需要几分钟。

#2


2  

ASP.NET MVC has a lot of plumbing infrastructure: for example, the routing engine which automatically invokes the right controller and action and can extract bits from the URL to pass as action arguments; or the convention-based location of views. It also provides more structure for passing data from the controller into the view (the ViewData object).

ASP.NET MVC有很多管道基础设施:例如,路由引擎自动调用正确的控制器和动作,并可以从URL中提取位作为动作参数传递;或基于会议的观点位置。它还提供了更多结构,用于将数据从控制器传递到视图(ViewData对象)。

Also, crucially, MVC supports view engines. You can write raw HTML with helpers in it, but you can also use view engines like Web Forms, Spark, NHaml, etc. which allow you to write more concise view code, create reusable components (e.g. Web Forms controls), etc. This wasn't possible in ASP Classic.

此外,至关重要的是,MVC支持视图引擎。您可以在其中编写带有帮助程序的原始HTML,但您也可以使用Web窗体,Spark,NHaml等视图引擎,它们允许您编写更简洁的视图代码,创建可重用的组件(例如Web窗体控件)等。在ASP Classic中是不可能的。

#3


0  

Classic ASP used VBScript, which does not have classes. It's not object-oriented at all.

经典ASP使用的是VBScript,它没有类。它根本不是面向对象的。

#4


0  

Very often with different technologies we can achieve the same final result. To create simple sites is almost irrelevant to the choice of technology. But when you want to make a large complex site the presence or absence of a framework that allows to optimize the code, keep well organized and efficiently divide may play a role crucial and greatly reduce the work.

通常使用不同的技术,我们可以获得相同的最终结果。创建简单网站几乎与技术选择无关。但是当你想要建立一个大型复杂站点时,是否存在允许优化代码的框架,保持良好的组织和有效的划分可能起到至关重要的作用,并大大减少工作量。

ASP Classic does not achieve the same results reached by asp net mvc.

ASP Classic没有达到asp net mvc达到的相同结果。

If we omit the obvious differences between c # vb script I would say that the difference main is that you can keep your code better organized.

如果我们省略c#vb脚本之间明显的差异,我会说主要的不同之处在于您可以更好地组织代码。

As with classic ASP is very easy to make "spaghetti code and, with asp mvc, on the contrary, it is very easy to keep everything tidy and separate the code business logic from display.

与经典的ASP一样,很容易制作“意大利面条代码,相反,使用asp mvc,很容易保持一切整洁,并将代码业务逻辑与显示分开。

Not only that.

不仅。

Asp Net Mvc seamlessly integrates with technologies such as that EntityFramework allow a further breakdown and organization of the code.

Asp Net Mvc与EntityFramework等技术无缝集成,允许进一步细分和组织代码。