Last week I was working on this really useful feature that is MembershipProvider. I had
to write my own implementation since I'm working on a custom database schema. I began to write my own
provider, and decided to test it.
Easy, I put a Login control on my login page, set some properties,
and launch the web site to see if it's working. Ok, it cannot work the first time, so I made little changes.
Among them, I hooked a method to the Authenticate event to check if it
at least passed through it.
It was executing it, but it still wouldn't execute any code in my provider!?
I continued to make some changes in config. It should work, but nothing.
Guess what ! When you hook the Authenticate event, the Login control
stops doing its default behavior - that is authenticating the user with the specified Membership provider -
and let you do all the work yourself ! That's why nothing happened, and I spent one day and a half on this!
This means that the OnAuthenticate methods that raise the events should look something like this:
protected bool OnAuthenticate(AuthenticateEventArgs e)
{
if (Authenticate != null)
{
Authenticate(this, e);
return e.Authenticated;
}
else
return DefaultAuthenticate();
}
It seams a bit error prone to me... what about adding a boolean Handled property to the
EventArg class to say that you did it on your own? Changing the behavior of a component
just because you hooked an event is a good way to drive developpers crazy...
Do you know other events with this behavior in the framework?