学习ASP.NET MVC第一件事应该就是Route。下面的图摘自的Dino的书:
![](https://img-blog.csdn.net/20130710112809453?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWxiZXJ0bGlhbmd5Zw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
由此粗略的学习可以归结于理解Routing Http Module和Http Handler.
Route Handler是Route Module的一部分:
public interface IRouteHandler
{
IHttpHandler GetHttpHandler(HttpContext requestContext);
}
Http Handler:
public class MvcEmuleHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
// Logic goes here
...
}
public Boolean IsReusable
{
get { return false; }
}
}
Routing Http Module和Http Handler的区别:
Routing Module 1)根据应用程序提供的route查看url 请求是否匹配; 2) 生成HttpContext以便handler使用。如果匹配则将请求传递给http handler,如果没有则返回一个Http 404 error。
Http Handler负责解析url 请求,实例化相应的Controller类,并调用相应的方法。
ASPX Engine中的Code Block
Code Block分两种。一是Inline Expression, 一是Inline Code。
Inline Expression are merely shortcuts for Response.Write and preface the expression with an = symbol. (<%= ViewData["message"] %>)
Inline Code block simply executes the specified code to create or modify some local state. (<% Run(); %>)