惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
V
V2EX
Jina AI
Jina AI
S
Schneier on Security
Cyberwarzone
Cyberwarzone
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
PCI Perspectives
PCI Perspectives
美团技术团队
小众软件
小众软件
L
LangChain Blog
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
T
Threatpost
T
Tor Project blog
K
Kaspersky official blog
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
H
Heimdal Security Blog
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
N
News | PayPal Newsroom
I
Intezer
博客园 - 聂微东
U
Unit 42
Cisco Talos Blog
Cisco Talos Blog
量子位
T
The Exploit Database - CXSecurity.com
Last Week in AI
Last Week in AI
博客园_首页
月光博客
月光博客
Webroot Blog
Webroot Blog
I
InfoQ
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
Project Zero
Project Zero
Hacker News: Ask HN
Hacker News: Ask HN
IT之家
IT之家
Google DeepMind News
Google DeepMind News
C
Cisco Blogs

博客园 - Jun1st

Application之间共享Master Page ASP.NET AJAX 4的Client-Side Template和DataView ASP.NET AJAX 4的Client-Side Template和DataView 体验ASP.NET4之ClientID 体验ASP.NET 4之URL Routing 使用Extension Methods来使IDataReader更加方便 Custom WCF Configuration File USE HttpRuntime.Cache OVER HttpContext.Current.Cache Make Asynchronous Calls from Page IIS and VS Embedded Local Web Server Integrate jQuery with ASP.NET Data Controls Tech-Ed 2008 上海 ASP.NET MVC的分页和导航 LINQ and Pipeline Pattern Why Would a .Net Programmer Learn Ruby On Rails(翻译) ASP.NET MVC之AJAX Asp.Net MVC---Walkthrough Asp.Net 2.0之SqlCacheDependency Security Basics and ASP.NET Support(翻译)
Asp.Net MVC 入门篇——Overview
Jun1st · 2008-05-24 · via 博客园 - Jun1st

2008-05-24 00:35  Jun1st  阅读(3823)  评论()    收藏  举报

Introduction

MVC应该算是一个古老的Design Pattern了,无论是在win form程序还是web程序中,它的应用都是比较广泛的。MVC也是我在学校中学习到的第一个设计模式。终于,可以在Asp.Net中应用了。本文的例子所用的是ASP.NET MVC Preview 2,可以在这里下载

Create a new MVC project

菜单File->New Project ->Asp.Net Web MVC Application

2.jpg

新创建的项目是一个完整的可以运行的Sample程序。
新创建的MVC Project和传统的Asp.net web application不同,MVC Project包含有如下四个文件夹:

  1. Content Folder : 这个文件夹中放一些支持文件,如CSS等。
  2. Controller Folder :这个文件夹中放所以的Controller文件
  3. Models folder : 这个文件夹存放所有的data model文件,包括:LINQ to SQL DBML文件,Entity文件
  4. Views folder : 存放所有的页面文件,包括master文件。Master等需要被共享访问的需要被放在一个Shared子文件夹中。

Advantages of an MVC-Based Web Application

  1. 把程序分为Model, View和Controller之后,更容易控制程序的复杂性
  2. 没有了传统的Asp.Net中的viewstate和server端的form,使得开发人员可以实现对页面的完全控制。当然也失去了viewstate和server端form带来的各种好处
  3. 支持测试驱动开发

Features of the ASP.NET MVC Framework

  1. 应用程序的业务分离,支持测试驱动开发
  2. 可扩展和支持插件的Framework。开发人员都可以根据自己的需要修改甚至替换Asp.Net MVC Framework的各个component,也可以以插件的形式开发自己的View Engine,URL Routing Policy等各种component。Asp.Net MVC Framework甚至支持依赖注入(Dependency Injection)和控制反转(Inversion of Control)等容器模式。
  3. 强大的URL-Mapping功能。使得URL地址更有意义(REST)。URL中不再包括文件扩展名。
  4. 对很多传统Asp.Net特性的支持。如<%=%>, user control等。

The MVC Framework and Postbacks

Asp.Net MVC 不再使用传统的Asp.Net Web Application的postback模式。取而代之的是,所有的客户端发回服务器端的request都会被映射到某一个controller类中,这使UI logic和business logic得以分离,从而有助于提高程序的可测试性。

Understanding the MVC Project Execution Process

Request被发回服务器端之后,首先都由UrlRoutingModule对象来解析这个Request,并根据URL找到一个匹配的Router对象,之后由这个Router对象来处理这个Request。 MVC Application的处理流程:

  1. Initial Request: routers在Global.ascx中被添加到RouteTable中。
  2. Routing: UrlRoutingModule找到匹配的Router对象,决定使用哪个controller,调用哪个action。
  3. Map to controller: MvcRouteHandler会尝试通过routedata来创建controller的type name.
  4. Create Controller
  5. Execute Controller