Share via


Ever wondered writing an HTTP Handler for WinForms

Today, I am writing an Application Event Handler Component (AEHC) for any WinForm Application in .NET. AEHC is an event handler for your winforms application, The primary functionality of this component is to raise an event after every forms load into memory. So that we can handle its event for performing any custom code processing and return the control to the form after processing.

Let’s consider a scenario, While implementing security into our application, we may have to disable or enable certain controls on every form according the role of the user accessing the form. For this we will call a custom method [for an instance AuthorizeMe()] to perform custom authentication and authorization from each and every form in our application. Suppose if in any case we forget to call its method from one of our form, in result there will be no security applied to that form.

Now, with AEHC we only call the method AuthorizeMe() once per application from AEHC and then its AEHC’s responsibility to execute AuthorizeMe() every time, after the form is loaded.

 

What is An Application Event Handler Component?
In ASP.NET, we can create custom HTTP Modules for adding custom processing to each and every Web Page in Web Application at a global level. One of the benefits you get using a HTTP Module is that you do not need to call them from each and every web page; they will automatically get executed for each of them. In Application Event Handler, you will achieve a similar functionality of HTTP Modules, however AEHC will be specific to every application in contrast with HTTP Modules which can be used machine wide.

Application Event Handler Component keeps track of the forms being loaded and unloaded throughout the application’s lifecycle and generate events like FormLoaded() and FormUnloaded() at Application level. Just like HTTP Modules, you too can write your own modules to manipulate the forms properties in these events....more to come asap.

I will be finishing this up soon, keep watching...

Comments

  • Anonymous
    November 11, 2004
    i think you can do something like this with MS UIP app block
  • Anonymous
    November 11, 2004
    Interesting.

    This is the same concept as the application events (in the My namespace) in VB2K5?

    Will be watching...