


Life cycle of asp.net MVC application (detailed explanation)_Practical tips
The following editor will share with you a detailed explanation of the life cycle based on asp.net MVC applications. It has a good reference value and I hope it will be helpful to everyone. If you are interested in asp.net, follow the editor to take a look.
First of all, we know that http is a stateless request. Its life cycle starts from the client browser sending a request to getting a response. Finish. So what does the MVC application do from making a request to getting a response?
In this article we will discuss in detail the life cycle of a request in an MVC application and how it is processed from one control to another. We will also introduce in detail the relevant components used in the entire request life cycle. Because in the normal development process, we may know how to use the MVC framework to process related requests. Most of the time we only do related processing between the controller and action methods, and may not know much about the real internal operating mechanism. . In fact, when we have a certain understanding of the internal mechanism, we will find that Microsoft's MVC framework is very extensible, with extension interfaces everywhere, allowing us to define the processing mechanism we need through extension. This is why The reason why the MVC framework is so famous.
When I first learned to use mvc, one of the questions that bothered me was, what is the process control of a request? What did you experience from view to controller to action? At that time, I didn't know what role the HTTP module and HTTP handler played in processing a request. After all, MVC is a web development framework, and the entire request processing process must include http module and http handler. In fact, there are many related components included in a complete MVC application request life cycle, and they all play a very important role in the entire request process. Although most of the time we use the default functions provided by the framework, if we understand the role of each control, we can easily extend and use our own methods. For now, MVC is an extension A relatively strong framework.
The following is the main content of this chapter:
HttpApplication
HttpModule
HttpHandler
ASP.NET MVC running mechanism
UrlRoutingModule
RouteHandler
MvcHandler
ControllerFactory
Controller
ActionInvoker
ActionResult
ViewEngine
HttpApplication
We all know that before the ASP.NET MVC framework appeared, the framework we used for most of our development was ASP.NET WebForm. In fact, whether it is MVC or WebForm, most of the request processing mechanisms are identical. This involves the processing of requests by IIS, which involves a lot of knowledge, so we will not introduce it. I will write a special article next time I have the opportunity. Let's start with HttpApplication. Let’s first take a look at how Microsoft officially defines HttpApplication:
Define the methods, properties, and events common to all application objects in the ASP.NET application. This class is the base class for applications defined by the user in the Global.asax file.
Maybe my translation is not very accurate, the original link is here: https://msdn.microsoft.com/en-us/library/system.web.httpapplication(v=vs. 110).aspx
There is a passage in Remark in Microsoft's official documentation: Instances of the HttpApplication class are created in the ASP.NET infrastructure, not directly by the user. Use an instance of the HttpApplication class to handle the many requests received during its lifetime. However, it can only handle one request at a time. This way, member variables can be used to store data for each request.
This means that an ASP.NET application, whether it is MVC or WebForm, will eventually reach an instance of the HttpApplication class. HttpApplication is the core of the entire ASP.NET infrastructure and is responsible for processing requests distributed to him. The request processing cycle of HttpApplication is a complex process. During the entire process, corresponding events will be triggered at different stages. We can register corresponding events and inject processing logic into a certain stage of HttpApplication processing requests. There are 19 events defined in the HttpApplication class to handle requests arriving at the HttpApplication instance. That is to say, regardless of MVC or WebForm, these 19 events will eventually be processed. So except for the request processing mechanisms just mentioned, MVC and WebFrom are mostly the same. What are the differences? Where did they start to go their separate ways? We guess it must be among these 19 methods. Let's continue reading.
Let’s take a look at these 19 events:
The application executes events handled by modules or user code defined in the global.asax file in the following order:
Event name: |
##Simple description: |
BeginRequest | Occurs as the first event in the HTTP execution pipeline chain when ASP.NET responds to a request |
AuthenticateRequest | Occurs when the security module has established a user identity. Note: The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request. Subscribing to the AuthenticateRequest event ensures that the request is authenticated before processing attached modules or |
PostAuthenticateRequest | Occurs when the security module has established a user identity. The PostAuthenticateRequest event is raised after the AuthenticateRequest event occurs. Functions that subscribe to the PostAuthenticateRequest event can access any data handled by PostAuthenticateRequest |
AuthorizeRequest | When the security module has authenticated the user Occurs when authorized. The AuthorizeRequest event signals that ASP.NET has authorized the current request. Subscribing to the AuthorizeRequest event ensures that the request is authenticated and authorized before the attached module or event handler is processed |
PostAuthorizeRequest | Occurs when the currently requesting user is authorized. The PostAuthorizeRequest event signals that ASP.NET has authorized the current request. Subscribing to the PostAuthorizeRequest event ensures that the request is authenticated and authorized before the attached module or handler is processed |
ResolveRequestCache | Occurs when ASP.NET completes an authorization event to cause the cache module to serve a request from the cache, thereby skipping the execution of an event handler (such as a page or XML Web service) |
PostResolveRequestCache | Occurs when ASP.NET skips execution of the current event handler and allows the cache module to satisfy the request from the cache. ) after the PostResolveRequestCache event and before the PostMapRequestHandler event (corresponding to the page requesting the URL |
Occurs when ASP.NET has mapped the current request to the appropriate event handler | |
Occurs when ASP.NET obtains the current state (such as session state) associated with the current request | #PostAcquireRequestState |
Occurs when the request state (such as session state) associated with the current request has been obtained |
#PreRequestHandlerExecute |
Occurs just before ASP.NET starts executing an event handler (for example, a page or an XML Web service) | ##PostRequestHandlerExecute |
#ReleaseRequestState. | ##Occurs after ASP.NET has executed all request event handlers.|
This event will cause the state module to save the current state data. ##PostReleaseRequestState |
Occurs when ASP.NET has completed executing all request event handlers and the request state data has been stored |
##UpdateRequestCache |
Occurs when ASP.NET has finished executing an event handler to enable the cache module to store the response that will be used to serve subsequent requests from the cache. |
PostUpdateRequestCache |
This event occurs after ASP.NET has completed updating the cache module and stored the response for serving subsequent requests from the cache. |
LogRequest |
Complete the update of the cache module in ASP.NET and store it for subsequent use from the cache This event occurs after requesting a response from the service. This event is only supported if IIS 7.0 is in integrated mode and the .NET Framework is at least version 3.0 |
##PostLogRequest
|
Occurs after ASP.NET has processed all event handlers for the LogRequest event. This event is only supported if IIS 7.0 is in integrated mode and the .NET Framework is at least version 3.0. |
EndRequest | Occurs as the last event in the HTTP execution pipeline chain when ASP.NET responds to a request. The EndRequest event is always raised when the CompleteRequest method is called. |
The above is the detailed content of Life cycle of asp.net MVC application (detailed explanation)_Practical tips. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











If you encounter the Unable to save changes error while using the Photos app for image editing in Windows 11, this article will provide you with solutions. Unable to save changes. An error occurred while saving. Please try again later. This problem usually occurs due to incorrect permission settings, file corruption, or system failure. So, we’ve done some deep research and compiled some of the most effective troubleshooting steps to help you resolve this issue and ensure you can continue to use the Microsoft Photos app seamlessly on your Windows 11 device. Fix Unable to Save Changes to Photos App Error in Windows 11 Many users have been talking about Microsoft Photos app error on different forums

What is Boundless Notes on iPhone? Like the iOS17 Diary app, Boundless Notes is a productivity app with tons of creative potential. It’s a great place to turn ideas into reality. You can schedule projects, brainstorm ideas, or create mood boards so you never run out of space to express your ideas. The app allows you to add photos, videos, audios, documents, PDFs, web links, stickers, and more anywhere on an unlimited canvas. Many of the tools in Boundless Notes (like brushes, shapes, and more) will be familiar to anyone who uses iWork apps like Keynote or Notes. Real-time collaboration with colleagues, teammates, and group project members is also easy because Freeform allows

The Apple Vision Pro headset is not natively compatible with computers, so you must configure it to connect to a Windows computer. Since its launch, Apple Vision Pro has been a hit, and with its cutting-edge features and extensive operability, it's easy to see why. Although you can make some adjustments to it to suit your PC, and its functionality depends heavily on AppleOS, so its functionality will be limited. How do I connect AppleVisionPro to my computer? 1. Verify system requirements You need the latest version of Windows 11 (Custom PCs and Surface devices are not supported) Support 64-bit 2GHZ or faster fast processor High-performance GPU, most

In Windows, the Photos app is a convenient way to view and manage photos and videos. Through this application, users can easily access their multimedia files without installing additional software. However, sometimes users may encounter some problems, such as encountering a "This file cannot be opened because the format is not supported" error message when using the Photos app, or file corruption when trying to open photos or videos. This situation can be confusing and inconvenient for users, requiring some investigation and fixes to resolve the issues. Users see the following error when they try to open photos or videos on the Photos app. Sorry, Photos cannot open this file because the format is not currently supported, or the file

When a friend's computer is missing certain files, the application cannot start normally with error code 0xc000012d. In fact, it can be solved by re-downloading the files and installing them. The application cannot start normally 0xc000012d: 1. First, the user needs to download ".netframework". 2. Then find the download address and download it to your computer. 3. Then double-click on the desktop to start running. 4. After the installation is completed, return to the wrong program location and open the program again.

View macOS Clipboard History from Finder When you copy anything on your Mac (text, images, files, URLs, etc.), it goes to the Clipboard. Here's how to see what was last copied on your Mac. Go to Finder and click "Edit" in the menu bar. Click "Show Clipboard". This will open a window showing the contents of the macOS clipboard. Get Clipboard History Containing Multiple Items in Mac Of course, native Mac Clipboard History isn't the most versatile tool you can have. It only shows the last thing you copied, so if you want to copy multiple things at once and then paste them all together, you simply can't do that. However, if you are looking for

Microsoft Paint not working in Windows 11/10? Well, this seems to be a common problem and we have some great solutions to fix it. Users have been complaining that when trying to use MSPaint, it doesn't work or open. Scrollbars in the app don't work, paste icons don't show up, crashes, etc. Luckily, we've collected some of the most effective troubleshooting methods to help you resolve issues with Microsoft Paint app. Why doesn't Microsoft Paint work? Some possible reasons why MSPaint is not working on Windows 11/10 PC are as follows: The security identifier is corrupted. hung system

Many users have been complaining about encountering error code caa90019 every time they try to log in using Microsoft Teams. Even though this is a convenient communication app, this mistake is very common. Fix Microsoft Teams Error: caa90019 In this case, the error message displayed by the system is: "Sorry, we are currently experiencing a problem." We have prepared a list of ultimate solutions that will help you resolve Microsoft Teams error caa90019. Preliminary steps Run as administrator Clear Microsoft Teams application cache Delete settings.json file Clear Microsoft from Credential Manager
