Interagir avec les pages ASP.NET avant l'Init.
J'ai tout d'abord pensé tripatouiller dans le fichier Global.asax... sans finalement avoir trouvé ce que je souhaitais. Par contre, en fouillant un peu du côté des HttpModule je suis arrivé à la solution suivante :
using System; using System.Reflection; using System.Web; using System.Web.UI; namespace Claymore.Web { /// /// /// public class ClaymoreHttpModule : IHttpModule { #region Fields private HttpApplication _application; #endregion /// /// Initializes a module and prepares it to handle requests. /// /// An that provides access to the methods, properties, and events common to all application objects within an ASP.NET application public void Init(HttpApplication context) { if(context == null) throw new ArgumentNullException("context"); _application = context; context.PostMapRequestHandler += onPostMapRequestHandler; } /// /// Disposes of the resources (other than memory) used by the module that implements . /// public void Dispose(){} /// /// Handle PostMapRequest event. /// /// The sender. /// The instance containing the event data. private void onPostMapRequestHandler(object sender, EventArgs e) { Page pageHandler; if ((pageHandler = _application.Context.Handler as Page) != null) pageHandler.PreInit += HandlePreInit; } /// /// Handles the pre init event. /// /// The sender. /// The instance containing the event data. protected virtual void HandlePreInit(object sender, EventArgs e) { Page page = sender as Page; if (page != null){ // Et voila, on a un pointeur sur une page, et l'on peut interagir avec elle avant l'événement Init. // Ajouter du code ici. } } } }
L'un d'entre vous connaîtrait-il une solution équivalente à base de HttpHandler ou autre?