SlideShare a Scribd company logo
1 of 2
HttpApplication Processing Pipeline 
MvcHandler 
Controller Creation 
Authentication and Authorization 
Action Method Invocation 
Model Binding 
Result Execution (View, etc.) 
Routing 
HTTP Request 
HTTP Response 
HttpApplication Processing Pipeline 
Action Invocation (with Filters) 
ASP.NET MVC 5 APPLICATION LIFECYCLE – HIGH-LEVEL VIEW 
This document shows the lifecycle of every ASP.NET MVC application, beginning from receiving the HTTP request from the client to sending the HTTP response back to the client. It is designed both as an education tool for those who are new to ASP.NET MVC and also as a reference for those who need to drill into specific aspects of the application.
HttpApplication Processing Pipeline 
Application_Start (in Global.asax.cs) 
HttpApplication.Init 
IHttpModule.Init 
HttpApplication.PostResolveRequestCache 
Invoke action with action filters (IActionFilter) 
Invoke authentication challenges (IAuthenticationFilter) 
Controller.Dispose 
Tasks to perform:  Common tasks such as register routes, bundles, and filters  Advance tasks such as set custom controller factory 
Override to subscribe to HttpApplication events 
Perform model binding on parameters 
Invoke authentication challenges (IAuthenticationFilter) 
false 
false 
Execute result 
Execute result with result filters (IResultFilter) 
Controller.EndExecute 
Controller.EndExecuteCore 
MvcHandler executes the controller action 
HttpApplication.BeginProcessRequestHttpApplication.EndProcessRequest 
HttpApplication Processing Pipeline 
HTTP Request 
HTTP Response 
ASP.NET MVC 5 APPLICATION LIFECYCLE – DETAIL VIEW 
Execute results with result filters (IResultFilter) 
Controller.OnResultExecuting 
<ResultFilter1>.OnResultExecuting 
<ResultFilter2>.OnResultExecuting 
Invoke action results (ActionResult.ExecuteResult) 
<ResultFilter2>.OnResultExecuted 
<ResultFilter1>.OnResultExecuted 
Controller.OnResultExecuted 
... 
... 
Find view fromview engines (RazorView, etc.) 
Write to HTTP response 
View, PartialView 
Other ActionResult types 
Render view 
Execute action method with action filters (IActionFilter) 
Controller.OnActionExecuting 
<ActionFilter1>.OnActionExecuting 
<ActionFilter2>.OnActionExecuting 
... 
<Named>Controller.<ActionAsync> 
Controller.EndExecute 
Controller.EndExecuteCore 
<Named>Controller.<Action> 
HttpApplication.BeginProcessRequestHttpApplication.EndProcessRequest 
<ActionFilter1>.OnActionExecuted 
Controller.OnActionExecuted 
<ActionFilter2>.OnActionExecuted 
... 
Asynchronous action methods (modified with the async keyword and returns Task<T>) are executed in HttpApplication.BeginProcessRequest 
Synchronous action methods (not modified with the async keyword) are executed in HttpApplication.EndProcessRequest 
Controller implements IActionFilter (by inheriting ActionFilterAttribute). OnActionExecuting methods are executed in order before the action method itself. 
OnActionExecuted methods are executed in reverse order after the action method itself. 
The diagram shows relevant HttpApplication stages to help you understand where MVC integrates into the ASP.NET application lifecycle. In addition, for the overridable methods on the Controller object that are part the MVC lifecycle, the diagram identifies when these methods are invoked in the processing pipeline and why you might want to override them. You may or may not have the need to override any one method, but It is important for you to understand their role in the application life cycle so that you can write code at the appropriate life cycle stage for the effect you intend. 
Color LegendHttpApplicationControllerAuthentication FiltersAuthorization FiltersAuthentication ChallengesAction ExecutionResult ExecutionRouting 
Called in HttpApplication.EndProcessRequest to end the controller execution. For asynchronous action methods, this portion of the pipeline may be invoked in a different worker thread. 
Controller implements IResultFilter (by inheriting ActionFilterAttribute). OnResultExecuting methods are executed in order before the result is executed. 
OnResultExecuted methods are executed in reverse order after the result is executed 
Invoke authentication filters (IAuthenticationFilter) Controller.OnAuthentication<IAuthenticationFilter1>.OnAuthentication<IAuthenticationFilter2>.OnAuthentication... If(AuthenticationContext.Result==null) If(AuthenticationContext.Result==null) If(AuthenticationContext.Result==null) StartEndtruetruetruefalsefalsefalseUse IAuthenticationFilter to authenticate a user action toward the intended resources. Authentication filters execute in order until one of the filters returns a non-null result. Invoke authentication challenges (IAuthenticationFilter) Controller.OnAuthenticationChallenge<IAuthenticationFilter1>.OnAuthenticationChallenge<IAuthenticationFilter2>.OnAuthenticationChallenge... StartEndAuthentication challenges are invoked whenever authentication or authorization filters return a result to indicate failure. They are also invoked after the action method executes in case the authentication scheme requires it, such as for server authentication to the client. Use OnAuthenticationChallenge to create the ActionResult you intend to send to the client when authentication challenges occur. When authentication challenges are invoked, all registered IAuthenticationFilter contribute to the result. Controller.OnAuthorization<IAuthorizationFilter1>.OnAuthorization<IAuthorizationFilter2>.OnAuthorization... If(AuthorizationContext.Result==null) If(AuthorizationContext.Result==null) If(AuthorizationContext.Result==null) StartEndtruetruetruefalsefalsefalseInvoke authorization filters (IAuthorizationFilter) Use IAuthorizationFilters to authorize a user action toward the intended resources. Authorization filters execute in order until one of the filters returns a non-null result. 
After authentication challenges are executed as a result of failed authentication or failed authorization, the result is executed immediately without any result filters. <Named>Controller.ctorController.BeginExecuteController.InitializeController.BeginExecuteCoreController.CreateTempDataProviderController.CreateActionInvokerOverride to perform custom initialization before ControllerBase.Initialize sets Controller.ControllerContext with the encapsulated route data. Override to perform processing before anything is done on the controllerOverride to use a custom TempData provider. SessionStateTempDataProvider is used by default. Override to use a custom action invoker. AsyncControllerActionInvoker is used by default. IControllerFactory.CreateControllerCalled by the MvcHandler to create the named controller. By default, DefaultControllerFactory is used. To register a custom IControllerFactory, use ControllerBuilder.Current.SetDefaultControllerFactory in Application_Start (in Global.asax.cs) Invoke authentication filters (IAuthenticationFilter) Invoke authorization filters (IAuthorizationFilter) If(AuthorizationContext.Result==null) If(AuthenticationChallengeContext.Result==null) truetrueHttpApplication.BeginProcessRequestHttpApplication.EndProcessRequestUrlRoutingModule.PostResolveRequestCacheMatch request to defined routeRetrieve MvcHandler as the HttpHandler for the request (stored at HttpApplication.Context.Handler) Store the encapsulated route data (at HttpApplication.Context.Request.RequestContext)

More Related Content

Recently uploaded

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Lifecycle of an aspnet mvc 5 application

  • 1. HttpApplication Processing Pipeline MvcHandler Controller Creation Authentication and Authorization Action Method Invocation Model Binding Result Execution (View, etc.) Routing HTTP Request HTTP Response HttpApplication Processing Pipeline Action Invocation (with Filters) ASP.NET MVC 5 APPLICATION LIFECYCLE – HIGH-LEVEL VIEW This document shows the lifecycle of every ASP.NET MVC application, beginning from receiving the HTTP request from the client to sending the HTTP response back to the client. It is designed both as an education tool for those who are new to ASP.NET MVC and also as a reference for those who need to drill into specific aspects of the application.
  • 2. HttpApplication Processing Pipeline Application_Start (in Global.asax.cs) HttpApplication.Init IHttpModule.Init HttpApplication.PostResolveRequestCache Invoke action with action filters (IActionFilter) Invoke authentication challenges (IAuthenticationFilter) Controller.Dispose Tasks to perform:  Common tasks such as register routes, bundles, and filters  Advance tasks such as set custom controller factory Override to subscribe to HttpApplication events Perform model binding on parameters Invoke authentication challenges (IAuthenticationFilter) false false Execute result Execute result with result filters (IResultFilter) Controller.EndExecute Controller.EndExecuteCore MvcHandler executes the controller action HttpApplication.BeginProcessRequestHttpApplication.EndProcessRequest HttpApplication Processing Pipeline HTTP Request HTTP Response ASP.NET MVC 5 APPLICATION LIFECYCLE – DETAIL VIEW Execute results with result filters (IResultFilter) Controller.OnResultExecuting <ResultFilter1>.OnResultExecuting <ResultFilter2>.OnResultExecuting Invoke action results (ActionResult.ExecuteResult) <ResultFilter2>.OnResultExecuted <ResultFilter1>.OnResultExecuted Controller.OnResultExecuted ... ... Find view fromview engines (RazorView, etc.) Write to HTTP response View, PartialView Other ActionResult types Render view Execute action method with action filters (IActionFilter) Controller.OnActionExecuting <ActionFilter1>.OnActionExecuting <ActionFilter2>.OnActionExecuting ... <Named>Controller.<ActionAsync> Controller.EndExecute Controller.EndExecuteCore <Named>Controller.<Action> HttpApplication.BeginProcessRequestHttpApplication.EndProcessRequest <ActionFilter1>.OnActionExecuted Controller.OnActionExecuted <ActionFilter2>.OnActionExecuted ... Asynchronous action methods (modified with the async keyword and returns Task<T>) are executed in HttpApplication.BeginProcessRequest Synchronous action methods (not modified with the async keyword) are executed in HttpApplication.EndProcessRequest Controller implements IActionFilter (by inheriting ActionFilterAttribute). OnActionExecuting methods are executed in order before the action method itself. OnActionExecuted methods are executed in reverse order after the action method itself. The diagram shows relevant HttpApplication stages to help you understand where MVC integrates into the ASP.NET application lifecycle. In addition, for the overridable methods on the Controller object that are part the MVC lifecycle, the diagram identifies when these methods are invoked in the processing pipeline and why you might want to override them. You may or may not have the need to override any one method, but It is important for you to understand their role in the application life cycle so that you can write code at the appropriate life cycle stage for the effect you intend. Color LegendHttpApplicationControllerAuthentication FiltersAuthorization FiltersAuthentication ChallengesAction ExecutionResult ExecutionRouting Called in HttpApplication.EndProcessRequest to end the controller execution. For asynchronous action methods, this portion of the pipeline may be invoked in a different worker thread. Controller implements IResultFilter (by inheriting ActionFilterAttribute). OnResultExecuting methods are executed in order before the result is executed. OnResultExecuted methods are executed in reverse order after the result is executed Invoke authentication filters (IAuthenticationFilter) Controller.OnAuthentication<IAuthenticationFilter1>.OnAuthentication<IAuthenticationFilter2>.OnAuthentication... If(AuthenticationContext.Result==null) If(AuthenticationContext.Result==null) If(AuthenticationContext.Result==null) StartEndtruetruetruefalsefalsefalseUse IAuthenticationFilter to authenticate a user action toward the intended resources. Authentication filters execute in order until one of the filters returns a non-null result. Invoke authentication challenges (IAuthenticationFilter) Controller.OnAuthenticationChallenge<IAuthenticationFilter1>.OnAuthenticationChallenge<IAuthenticationFilter2>.OnAuthenticationChallenge... StartEndAuthentication challenges are invoked whenever authentication or authorization filters return a result to indicate failure. They are also invoked after the action method executes in case the authentication scheme requires it, such as for server authentication to the client. Use OnAuthenticationChallenge to create the ActionResult you intend to send to the client when authentication challenges occur. When authentication challenges are invoked, all registered IAuthenticationFilter contribute to the result. Controller.OnAuthorization<IAuthorizationFilter1>.OnAuthorization<IAuthorizationFilter2>.OnAuthorization... If(AuthorizationContext.Result==null) If(AuthorizationContext.Result==null) If(AuthorizationContext.Result==null) StartEndtruetruetruefalsefalsefalseInvoke authorization filters (IAuthorizationFilter) Use IAuthorizationFilters to authorize a user action toward the intended resources. Authorization filters execute in order until one of the filters returns a non-null result. After authentication challenges are executed as a result of failed authentication or failed authorization, the result is executed immediately without any result filters. <Named>Controller.ctorController.BeginExecuteController.InitializeController.BeginExecuteCoreController.CreateTempDataProviderController.CreateActionInvokerOverride to perform custom initialization before ControllerBase.Initialize sets Controller.ControllerContext with the encapsulated route data. Override to perform processing before anything is done on the controllerOverride to use a custom TempData provider. SessionStateTempDataProvider is used by default. Override to use a custom action invoker. AsyncControllerActionInvoker is used by default. IControllerFactory.CreateControllerCalled by the MvcHandler to create the named controller. By default, DefaultControllerFactory is used. To register a custom IControllerFactory, use ControllerBuilder.Current.SetDefaultControllerFactory in Application_Start (in Global.asax.cs) Invoke authentication filters (IAuthenticationFilter) Invoke authorization filters (IAuthorizationFilter) If(AuthorizationContext.Result==null) If(AuthenticationChallengeContext.Result==null) truetrueHttpApplication.BeginProcessRequestHttpApplication.EndProcessRequestUrlRoutingModule.PostResolveRequestCacheMatch request to defined routeRetrieve MvcHandler as the HttpHandler for the request (stored at HttpApplication.Context.Handler) Store the encapsulated route data (at HttpApplication.Context.Request.RequestContext)