本文介绍了如何ASP.Net MVC从经典ASP( - 原来ASP不ASP.Net)的不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让ASP.Net MVC的高层次的理解,它已开始发生,我认为它看起来很像原始的ASP脚本。早在一天,我们正在组织我们的模式/业务逻辑code VBScript中的类,或进入VB COM组件。

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.

当然,现在我们的C#和.NET框架类的额外功率。除了高水平的面向对象和C#和.NET等能力,什么是原来的ASP和ASP.Net MVC之间的另一个主要区别是什么?

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?

推荐答案

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

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

使用传统的ASP有从编写HTML页面写入动态内容的HTML页面的平稳过渡。与静态的HTML文件,每个URL具有一个直接映射到文件系统中的一个文件。同样的事情是ASP.NET或多或少真的,因为它的价值。

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.NET MVC中,每个网址映射到控制器对象(存储在/ Controllers目录,默认情况下),在那里访问时,每个家庭成员调用方法的家庭。在每一个方法(典型值)的结尾,你告诉它渲染特定视图(存储在在/ views目录控制器命名的文件夹中),这是很多像一个传统的ASP页面,所有的逻辑分离出来。

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.

这给你的逻辑和搜索引擎友好的URL和相关的功能一起群体。

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

在传统的ASP这是常见的发现,其中一些HTML都包含在顶部页,然后一个数据库连接被打开,而被输出给用户,然后再有更多的HTML有些事情是从数据库中读取,然后另一个数据库语句,等等。

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.NET MVC中,你的业务逻辑(例如验证)云在模型层(你可以从几十的一个选择,但流行的选择是LINQ到SQL和LINQ到实体框架)您的人机界面逻辑是在控制器(例如填充根据国家选择国家/省菜单),你的presentation(实际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.

除了保持一切井井有条,这有助于大量具有能够编写自动化测试的东西。您可以发送一个嘲笑向上对象到您的视图,并确保它看起来不错,你可以坏的数据发送到你的模型,并确保它抱怨,你可以确保你的控制器发送到您的视图对象是一致它从模型中读取数据。

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.

ASP.NET是强类型和编译。这是一个双刃剑。在一方面,它会在编译的时候赶上了很多愚蠢的程序员的错误。在另一方面它,那意味着你留下了无限减一在您的code可能出现的错误(单元测试可以把它无限减去一些更大的数字)。此外,你必须做这样的事情:

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:

if (MyArray.Length > 0)

而不是

if (MyArray.Length)

但恕我直言,这是一个很小的代价为速度和完整性检查你强类型得到。

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

更大的缺点编译语言在一个大的框架是部署变得更加生产比它的东西,如经典ASP。你不能两个文件直接复制到Web服务器来更新您的应用程序。您通常必须采取的网络服务器下跌(希望你有一对冗余)并重新编译,这可能需要几分钟。

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.

这篇关于如何ASP.Net MVC从经典ASP( - 原来ASP不ASP.Net)的不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:08