Asp.net AutoEventWireup and reflection?

AutoEventWireup uses reflection search methods using page_eventName

msdn

When AutoEventWireup is true, handlers are automatically tied to runtime events based on their name and signature. For each event, ASP.NET looks for a method that is specified according to the Page_eventname pattern, for example, Page_Load or Page_Init.

Question:

Does he do this for every request?

I looked in temporary internet files (in the Microsoft.net folder ...) to see if it would save another file containing an explicit attachment attachment, and could not find it.

+4
source share
1 answer

ASP.NET seems to use a cache for this, as @Marc said. See Internal TemplateControl.HookUpAutomaticHandlers .

Part of this method with dotPeek :

 internal void HookUpAutomaticHandlers() { ... object obj = TemplateControl._eventListCache[(object) this.GetType()]; if (obj == null) { lock (TemplateControl._lockObject) { obj = TemplateControl._eventListCache[(object) this.GetType()]; if (obj == null) { IDictionary local_1_1 = (IDictionary) new ListDictionary(); this.GetDelegateInformation(local_1_1); obj = local_1_1.Count != 0 ? (object) local_1_1 : TemplateControl._emptyEventSingleton; TemplateControl._eventListCache[(object) this.GetType()] = obj; } } } ... 

The private GetDelegateInformation method is responsible for creating delegates for the control. TemplateControl._eventListCache is a Hashtable that contains delegates for each template control.

So, answering your question:

Does he do this for every request?

The answer is no. ASP.NET does this to populate this Hashtable , and then uses cached values.

+4
source

Source: https://habr.com/ru/post/1445991/


All Articles