什么,为什么或何时最好选择cshtml与aspx? [英] What, why or when it is better to choose cshtml vs aspx?

查看:247
本文介绍了什么,为什么或何时最好选择cshtml与aspx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么,为什么或何时选择cshtml以及什么,为何或何时选择aspx技术?这两种技术是干什么用的?

I would like to know what, why or when it is better to choose cshtml and what, why or when it is better to choose aspx technologies? What are these two technologies intended for?

谢谢

推荐答案

正如其他人回答的那样,.cshtml(或.vbhtml(如果您喜欢的话))提供了一个处理程序映射来加载MVC引擎. .aspx扩展名仅加载执行编译并提供Web表单的aspnet_isapi.dll.处理程序映射中的差异只是一种允许两者共存于同一服务器上的方法,从而允许MVC应用程序和WebForms应用程序都位于同一根目录下.

As other people have answered, .cshtml (or .vbhtml if that's your flavor) provides a handler-mapping to load the MVC engine. The .aspx extension simply loads the aspnet_isapi.dll that performs the compile and serves up web forms. The difference in the handler mapping is simply a method of allowing the two to co-exist on the same server allowing both MVC applications and WebForms applications to live under a common root.

这允许 http://www.mydomain.com/MyMVCApplication 有效并与MVC一起使用规则以及 http://www.mydomain.com/MyWebFormsApplication 作为标准Web表单有效.

This allows http://www.mydomain.com/MyMVCApplication to be valid and served with MVC rules along with http://www.mydomain.com/MyWebFormsApplication to be valid as a standard web form.


至于技术上的差异,MVC(Razor)模板框架旨在将.Net页面返回到更RESTful的基于Web的模板视图平台,该平台将模型(业务/数据对象),模型之间的代码逻辑分开.视图(用户看到的内容)和控制器(两者之间的连接). WebForms模型(aspx)是Microsoft尝试使用复杂的javascript嵌入来模拟更具状态的应用程序,类似于WinForms应用程序,该应用程序具有事件和页面生命周期,该事件和页面生命周期能够在页面之间保留其自身的状态.


As for the difference in the technologies, the MVC (Razor) templating framework is intended to return .Net pages to a more RESTful "web-based" platform of templated views separating the code logic between the model (business/data objects), the view (what the user sees) and the controllers (the connection between the two). The WebForms model (aspx) was an attempt by Microsoft to use complex javascript embedding to simulate a more stateful application similar to a WinForms application complete with events and a page lifecycle that would be capable of retaining its own state from page to page.

使用一个或另一个选择总是一个有争议的选择,因为存在对两个系统都支持和反对的争论.我喜欢MVC架构中的简单性(尽管路由很简单)和Razor语法的简单性.我觉得WebForms架构太重了,无法成为有效的Web平台.话虽这么说,但在许多实例中,WebForms框架提供了一个非常简洁和可用的模型,并具有定义明确的丰富事件结构.一切都归结为应用程序的需求以及构建它的人的喜好.

The choice to use one or the other is always going to be a contentious one because there are arguments for and against both systems. I for one like the simplicity in the MVC architecture (though routing is anything but simple) and the ease of the Razor syntax. I feel the WebForms architecture is just too heavy to be an effective web platform. That being said, there are a lot of instances where the WebForms framework provides a very succinct and usable model with a rich event structure that is well defined. It all boils down to the needs of the application and the preferences of those building it.

这篇关于什么,为什么或何时最好选择cshtml与aspx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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