13. 练习 1
1. routes.MapRoute("CustomRoute ", "{controller}/
{action}", new { controller = "Home", action
="Index" })
URL Match ?
http://testsite.com/
http://testsite.com/Home
http://testsite.com/Test/Demo
http://testsite.com//Demo
http://testsite.com/Test/Demo/List
Y
Y
Y
N
N
17. Filter
AOP 简介
MVC 中的切面 (aspect)
1. Before Action
Public ActionResule ActionMethod()
{
//My Business Code
……
2. After Action
3. Before result
return View();
}
4. After Result
18. 系统提供的一些 Filter
Filter Typ
e
实现接口 执行时间 Default Implementation
Authorizatio
n filter
IAuthorizatio
nFilter
在所有 Filter 和
Action 执行之前
执行
AuthorizeAttribute
Action filter IActionFilter 分别在 Action 执行
之前和之后执行
。
ActionFilterAttribute
Result filter IResultFilter 分别在
Action Result 执
行之后和之前
ResultFilterAttribute
Exception filt
er
IExceptionFil
ter
只有在 filter, HandleErrorAttribute
或
者 action meth
od, 或
者 action result
抛出一个异常时
候执行
33. 推荐资源
Pro ASP.NET MVC 3 Framework 3rd Edition
http://ishare.iask.sina.com.cn/f/23501178.html
creating views with MvcContrib.FluentHtml
http://www.arrangeactassert.com/asp-net-mvc-view-best-
practices-save-time-creating-views-with-mvccontrib-
fluenthtml/
Editor's Notes
需要注意 MVC 并不是很多人理解上的三层架构 , 3-tier or N-tier is : WebPage -- BLL – DAL, Monorail Castle Project 是另外一个第三方的 asp.net MVC 实现 优点: 将不同的功能作更明确地切割,让不同专长的技术人员各司其职,也顺便提高了代码的可读性,便于测试 并达到「松散耦合 (loosely coupled) 」,让组件易于更换和重复使用 ASP.NET 程序员必须先改变过去,把很多业务逻辑、输入验证、页面切换…等杂七杂八的功能,全部写在 Code-Behind (aspx.cs) 里的旧习惯
1. Step 1 – The RouteTable is Created ( 仅调用一次 ) An application’s Route Table is represented by the static RouteTable.Routes property. 2. Step 2 – The UrlRoutingModule Intercepts the Request This second step happens whenever you make a request. The UrlRoutingModule intercepts every request and creates and executes the right handler. 3. Step 3 – The MvcHandler Executes The MvcHandler creates a controller, passes the controller a ControllerContext, and executes the controller. 4. Step 4 – The Controller Executes The controller determines which controller method to execute, builds a list of parameters, and executes the method. 5. Step 5 – The RenderView Method is Called Typically, a controller method calls RenderView() to render content back to the browser. The Controller.RenderView() method delegates its work to a particular ViewEngine.