• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    ASP.NET MVC 从IHttp到页面输出的实例代码

    复制代码 代码如下:

    MVCHandler : IHttpHandler
    void IHttpHandler.ProcessRequest(HttpContext httpContext)
    {
        this.ProcessRequest(httpContext);
    }

    protected virtual void ProcessRequest(HttpContext httpContext)
    {
        HttpContextBase base2 = new HttpContextWrapper(httpContext);
        this.ProcessRequest(base2);
    }

    protected internal virtual void ProcessRequest(HttpContextBase httpContext)
    {
        IController controller;
        IControllerFactory factory;
        this.ProcessRequestInit(httpContext, out controller, out factory);
        try
        {
            controller.Execute(this.RequestContext);
        }
        finally
        {
            factory.ReleaseController(controller);
        }
    }       

    复制代码 代码如下:

    Controller : ControllerBase : IController
    void IController.Execute(RequestContext requestContext)  //------>Controller
    {
        this.Execute(requestContext);
    }

    protected virtual void Execute(RequestContext requestContext)   //------>ControllerBase
    {
        if (requestContext == null)
        {
            throw new ArgumentNullException("requestContext");
        }
        if (requestContext.HttpContext == null)
        {
            throw new ArgumentException(MvcResources.ControllerBase_CannotExecuteWithNullHttpContext, "requestContext");
        }
        this.VerifyExecuteCalledOnce();
        this.Initialize(requestContext);
        using (ScopeStorage.CreateTransientScope())
        {
            this.ExecuteCore();
        }
    }

    protected override void ExecuteCore()   //------>Controller
    {
        this.PossiblyLoadTempData();
        try
        {
            string requiredString = this.RouteData.GetRequiredString("action");
            if (!this.ActionInvoker.InvokeAction(base.ControllerContext, requiredString))   //public IActionInvoker ActionInvoker { get; set; }
            {
                this.HandleUnknownAction(requiredString);
            }
        }
        finally
        {
            this.PossiblySaveTempData();
        }
    }

    复制代码 代码如下:

    ControllerActionInvoker : IActionInvoker
    public virtual bool InvokeAction(ControllerContext controllerContext, string actionName)
    {
        if (controllerContext == null)
        {
            throw new ArgumentNullException("controllerContext");
        }
        if (string.IsNullOrEmpty(actionName))
        {
            throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
        }
        ControllerDescriptor controllerDescriptor = this.GetControllerDescriptor(controllerContext);
        ActionDescriptor actionDescriptor = this.FindAction(controllerContext, controllerDescriptor, actionName);
        if (actionDescriptor == null)
        {
            return false;
        }
        FilterInfo filters = this.GetFilters(controllerContext, actionDescriptor);
        try
        {
            AuthorizationContext context = this.InvokeAuthorizationFilters(controllerContext, filters.AuthorizationFilters, actionDescriptor);
            if (context.Result != null)
            {
                this.InvokeActionResult(controllerContext, context.Result);
            }
            else
            {
                if (controllerContext.Controller.ValidateRequest)
                {
                    ValidateRequest(controllerContext);
                }
                IDictionarystring, object> parameterValues = this.GetParameterValues(controllerContext, actionDescriptor);
                ActionExecutedContext context2 = this.InvokeActionMethodWithFilters(controllerContext, filters.ActionFilters, actionDescriptor, parameterValues);
                this.InvokeActionResultWithFilters(controllerContext, filters.ResultFilters, context2.Result);
            }
        }
        catch (ThreadAbortException)
        {
            throw;
        }
        catch (Exception exception)
        {
            ExceptionContext context3 = this.InvokeExceptionFilters(controllerContext, filters.ExceptionFilters, exception);
            if (!context3.ExceptionHandled)
            {
                throw;
            }
            this.InvokeActionResult(controllerContext, context3.Result);
        }
        return true;
    }

    protected virtual void InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
    {
        actionResult.ExecuteResult(controllerContext);
    }

    复制代码 代码如下:

    ActionResult
    public override void ExecuteResult(ControllerContext context)
    {
        if (context == null)
        {
            throw new ArgumentNullException("context");
        }
        if (string.IsNullOrEmpty(this.ViewName))
        {
            this.ViewName = context.RouteData.GetRequiredString("action");
        }
        ViewEngineResult result = null;
        if (this.View == null)
        {
            result = this.FindView(context);   //ViewEngineResult
            this.View = result.View;    //IView接口   
        }
        TextWriter output = context.HttpContext.Response.Output;
        ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, output);
        this.View.Render(viewContext, output);
        if (result != null)
        {
            result.ViewEngine.ReleaseView(context, this.View);
        }
    }

    您可能感兴趣的文章:
    • ASP.NET小结之MVC, MVP, MVVM比较以及区别(一)
    • ASP.NET mvc异常处理的方法示例介绍
    • .NET Web开发之.NET MVC框架介绍
    • ASP.NET MVC3 实现全站重定向的简单方法
    • ASP.NET小结之MVC, MVP, MVVM比较以及区别(二)
    上一篇:在子页中隐藏模板页中的div示例代码
    下一篇:关于Asp.net页面Page_Load被执行两次的问题分享
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    ASP.NET MVC 从IHttp到页面输出的实例代码 ASP.NET,MVC,从,IHttp,到,页面,