Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to output ASP.NET MVC from IHttp to Page

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to output ASP.NET MVC from IHttp to the page. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The code is as follows:

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)

}

}

The code is as follows:

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 ()

}

}

The code is as follows:

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)

}

IDictionary 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)

}

The code is as follows:

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 interface

}

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)

}

}

On "ASP.NET MVC how to IHttp to page output" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report