سه شنبه , ۳۱ اردیبهشت ۱۳۹۸
خانه - #C - چرخه عمر درخواست ها در ASP MVC

چرخه عمر درخواست ها در ASP MVC

در این مقاله به بررسی طول عمر و اتفاقاتی که برای یک درخواست Http از لحظه فرستادن آن برای سرور تا ساخت پاسخ و نمایش آن در مرورگر بحث خواهیم کرد.

 

وقتی شما یک Action را در mvc صدا می زنید تمام چیزی که اتفاق می افتد دقیقا مانند این است که یک متد را با پارامتر هایش صدا بزنید. اینکه چگونه ما از یک درخواست http  به فراخوانی یک متد با پارامتر هایش می رسیم. موضوعی است که اینجا در مورد آن صحبت خواهیم کرد. در اینجا سعی خواهیم کرد تا به طور کامل شرح دهیم که چ اتفاقی برای یک درخواست Http  می افتد. یک سفر به درون فریم ورک می تواند خیلی خیلی برای حل بعضی از مسایل مفید باشد.

BeginRequest Event

The BeginRequest event signals the creation of any given new request. This event is always raised and is always the first event to occur during the processing of a request.

AuthenticateRequestEvent

The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request. Subscribing to the AuthenticateRequest event ensures that the request will be authenticated before processing the attached module or event handler.

PostAuthenticateRequest Event

The PostAuthenticateRequest event is raised after the AuthenticateRequest event has occurred. Functionality that subscribes to the PostAuthenticateRequest event can access any data that is processed by the PostAuthenticateRequest.

AuthorizeRequestEvent

The AuthorizeRequest event signals that ASP.NET has authorized the current request. Subscribing to the AuthorizeRequest event ensures that the request will be authenticated and authorized before processing the attached module or event handler.

AuthorizeRequestEvent

The PostAuthorizeRequest event signals that ASP.NET has authorized the current request. Subscribing to the PostAuthorizeRequest event ensures authentication and authorization of the request before processing the attached module or event handler.

PostAuthorizeRequestEvent

The PostAuthorizeRequest event signals that ASP.NET has authorized the current request. Subscribing to the PostAuthorizeRequest event ensures authentication and authorization of the request before processing the attached module or event handler.

ResolveRequestCacheEvent

Occurs when ASP.NET finishes an authorization event to let the caching modules serve requests from the cache, bypassing execution of the event handler (for example, a page or an XML Web service).

PostResolveRequestCache Event

Occurs when ASP.NET bypasses execution of the current event handler and allows a caching module to serve a request from the cache.

After the PostResolveRequestCache event and before the PostMapRequestHandler event, an event handler (which is a page that corresponds to the request URL) is created. When a server is running IIS 7.0 in Integrated mode and at least the .NET Framework version 3.0, the MapRequestHandler event is raised. When a server is running IIS 7.0 in Classic mode or an earlier version of IIS, this event cannot be handled.

MapRequestHandlerEvent

The MapRequestHandler event is used by the ASP.NET infrastructure to determine the request handler for the current request. For more information, see How to: Register HTTP Handlers.

PostMapRequestHandler Event

Occurs when ASP.NET has mapped the current request to the appropriate event handler.

AcquireRequestStateEvent


Occurs when ASP.NET acquires the current state (for example, session state) that is associated with the current request.

PostAcquireRequestState Event


The PostAcquireRequestState event is raised after the AcquireRequestState event has occurred. Functionality that subscribes to the AcquireRequestState event can access any data that is processed by the PostAcquireRequestState.

PreRequestHandlerExecute Event

Occurs just before ASP.NET starts executing an event handler (for example, a page or an XML Web service).

The event handler is executed.

PostRequestHandlerExecute Event

Occurs when the ASP.NET event handler (for example, a page or an XML Web service) finishes execution.

ReleaseRequestStateEvent

Occurs after ASP.NET finishes executing all request event handlers. This event causes state modules to save the current state data.

PostReleaseRequestState Event

Occurs when ASP.NET has completed executing all request event handlers and the request state data has been stored.

After the PostReleaseRequestState event is raised, any existing response filters will filter the output.

UpdateRequestCacheEvent

Occurs when ASP.NET finishes executing an event handler in order to let caching modules store responses that will be used to serve subsequent requests from the cache.

PostUpdateRequestCache Event

Occurs when ASP.NET finishes updating caching modules and storing responses that are used to serve subsequent requests from the cache.

The PostUpdateRequestCache event is raised after the UpdateRequestCache event has occurred. When the PostUpdateRequestCache is raised, ASP.NET has completed processing code and the content of the cache is finalized.

LogRequest Event

Occurs just before ASP.NET performs any logging for the current request.
The LogRequest event is raised even if an error occurs. You can provide an event handler for the LogRequest event to provide custom logging for the request.

The following example demonstrates how to provide an event handler for the LogRequest event. The event handler also handles several other events. Therefore, the CurrentNotification and IsPostNotification properties are used to determine what code to run.

using System;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
// Module that demonstrates one event handler for several events.
namespace Samples
{
public class ModuleExampleTestCS : IHttpModule
{
public ModuleExampleTestCS()
{
// Constructor
}
public void Init(HttpApplication app)
{
app.AuthenticateRequest += new EventHandler(App_Handler);
app.PostAuthenticateRequest += new EventHandler(App_Handler);
app.LogRequest += new EventHandler(App_Handler);
app.PostLogRequest += new EventHandler(App_Handler);
}
public void Dispose()
{
}
// One handler for AuthenticationRequest, PostAuthenticateRequest,
// LogRequest, and PostLogRequest events
public void App_Handler(object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
HttpContext context = app.Context;
if (context.CurrentNotification == RequestNotification.AuthenticateRequest)
{
if(!context.IsPostNotification)
{
// Put code here that is invoked when the AuthenticateRequest event is raised. } else { // PostAuthenticateRequest // Put code here that runs after the AuthenticateRequest event completes. } } if (context.CurrentNotification == RequestNotification.LogRequest) { if (!context.IsPostNotification) { // Put code here that is invoked when the LogRequest event is raised. } else { // PostLogRequest // Put code here that runs after the LogRequest event completes. } } }}
}

PostLogRequest Event

Occurs when ASP.NET has completed processing all the event handlers for the LogRequest event.

EndRequest Event


Occurs as the last event in the HTTP pipeline chain of execution when ASP.NET responds to a request.

منبع

درباره ی محمد لطفی

برنامه نویس و توسعه دهنده

همچنین ببینید

ASP.NET-CORE-Routing

مسیریابی در ASP.NET Core

مسیریابی در ASP.NET Core به مکانیسمی گفته می شود که آدرس کامل را از درخواست Http  …

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *