public class MvcHandler : IHttpAsyncHandler IHttpHandler IRequiresSessionState
{
//其他成员
public RequestContext RequestContext { get; private set; }
public bool IsReusable
{
get { return false; }
}
public MvcHandler(RequestContext requestContext)
{
thisRequestContext = requestContext;
}
IAsyncResult BeginProcessRequest(HttpContext context AsyncCallback cb
object extraData)
{
IControllerFactory controllerFactory =
ControllerBuilderCurrentGetControllerFactory()
string controllerName =
thisRequestContextRouteDataGetRequiredString(controller)
IController controller = controllerFactory
CreateController(thisRequestContext controllerName)
if (controller is IAsyncController)
{
try
{
//调用BeginExecute/EndExecute方法以异步的方式执行Controller
}
finally
{
controllerFactoryReleaseController(controller)
}
}
else
{
try
{
//调用Execute方法以异步的方式执行Controller
}
finally
{
controllerFactoryReleaseController(controller)
}
}
}
}
由于MvcHandler同时实现了IHttpHandler和IHttpAsyncHandler接口所以它总是以异步的方式被执行(调用BeginProcessRequest/EndProcessRequest方法)BeginProcessRequest方法通过RequestContext对象得到目标Controller的名称然后利用当前ControllerBuilder创建的ControllerFactory激活Controller对象如果Controller类型实现了IAsyncController接口则以异步的方式执行Controller否则采用同步执行方式在被激活Controller对象被执行之后MvcHandler会调用ControllerFactory的ReleaseController对其进行释放清理工作
返回目录ASPNET MVC 框架揭秘
编辑推荐
ASP NET开发培训视频教程
Microsoft NET框架程序设计视频教程
Java程序性能优化让你的Java程序更快更稳定
Visual C++音频/视频技术开发与实战
[] []