K
Keith Mattson
Hi all,
I'm trying to write my own ASP.NET membership "system", and that
system does NOT derive or inherit from ASP.NET's own Membership
Provider model. I do, however, want to (more or less) "mimic" the way
that ASP.NET's membership providers work.
Whilst this may well sound like re-inventing the wheel, my reason for
doing it is this: I have tried to write a custom membership provider
that DID derive from ASP.NET's own provider model, with a class
inheriting from MembershipProvider, and another inheriting from
MembershipUser.
All I realy wanted to do was to add some simple, additional "fields"
to the user class. The major problem that I ran into was the
CreateUser method that must be overridden in your own derived class.
This method takes a series of parameters based upon the fields in
Microsoft's own "user" class. Of course, mine had additional fields,
so I could not change the methods signature to include my own fields.
Then I hit upon an idea. I decided that if I wrote my own "membership
provider" that did not derive from MembershipProvider or
MembershipUser, I could make it very generic. My idea is to have a
base class (MyMembershipUserBase) that would contain an amount of
fields that are requirements for the membership system (things like
username, password, createddate etc.).
Consumers of my "membership" system, could create thier own custom
user class, which must inherit from my base class, and could then add
thier own fields that they cared to store in the backend database.
I've even got public attributes that must decorate each field's
property accessor to inform my membership system of the relevant
database field name and datatype when persisting the new
consumer-created fields.
My own "Membership" class that contains all of the actual methods to
Create, Update, Delete (etc) user would accept parameters as my own
"base" type, and through the wonders of polymorphism and .NET's own
reflection, I would iterate through the passed in object that derives
from my own base type and figure out which new properties the
"consumer" had added, and persist those the the database (using the
attributes provided for each consumer-created property).
I was going great guns with all of this, until I remembered about such
things as IPrincipal and the forms authentication system. This is
where I'm struggling slightly. I believe that my "user" base class
should implement the IPrincipal interface, but I'm not quite sure what
code I need to put in the implemented methods from this interface.
Also, I'd like the consumer of my membership system to be able to do
things like:
HttpRequest.Current.User.Identity
HttpRequest.Current.User.IsAuthenticated
etc.
and retrieve the "custom" created user object that derives from my own
user base class (or one of it's properties). I'd like the consumer to
be able to do this without having to assign anything to
HttpRequest.Current.User themselves, however, I'm struggling with
where any assignment to to the HttpRequest.Current.User should go
within my own membership system's code.
Basically, I'd like to know how the built-in ASP.NET provider model
uses and utilises the IPrincipal interface (and possibly also the
IIdentity interface) so that I can then, hopefully, replicate that
within my own membership system code.
Anyone have advanced knowledge of how all of these things are
implemented and fit together?
Thanks in advance.
Keith.
I'm trying to write my own ASP.NET membership "system", and that
system does NOT derive or inherit from ASP.NET's own Membership
Provider model. I do, however, want to (more or less) "mimic" the way
that ASP.NET's membership providers work.
Whilst this may well sound like re-inventing the wheel, my reason for
doing it is this: I have tried to write a custom membership provider
that DID derive from ASP.NET's own provider model, with a class
inheriting from MembershipProvider, and another inheriting from
MembershipUser.
All I realy wanted to do was to add some simple, additional "fields"
to the user class. The major problem that I ran into was the
CreateUser method that must be overridden in your own derived class.
This method takes a series of parameters based upon the fields in
Microsoft's own "user" class. Of course, mine had additional fields,
so I could not change the methods signature to include my own fields.
Then I hit upon an idea. I decided that if I wrote my own "membership
provider" that did not derive from MembershipProvider or
MembershipUser, I could make it very generic. My idea is to have a
base class (MyMembershipUserBase) that would contain an amount of
fields that are requirements for the membership system (things like
username, password, createddate etc.).
Consumers of my "membership" system, could create thier own custom
user class, which must inherit from my base class, and could then add
thier own fields that they cared to store in the backend database.
I've even got public attributes that must decorate each field's
property accessor to inform my membership system of the relevant
database field name and datatype when persisting the new
consumer-created fields.
My own "Membership" class that contains all of the actual methods to
Create, Update, Delete (etc) user would accept parameters as my own
"base" type, and through the wonders of polymorphism and .NET's own
reflection, I would iterate through the passed in object that derives
from my own base type and figure out which new properties the
"consumer" had added, and persist those the the database (using the
attributes provided for each consumer-created property).
I was going great guns with all of this, until I remembered about such
things as IPrincipal and the forms authentication system. This is
where I'm struggling slightly. I believe that my "user" base class
should implement the IPrincipal interface, but I'm not quite sure what
code I need to put in the implemented methods from this interface.
Also, I'd like the consumer of my membership system to be able to do
things like:
HttpRequest.Current.User.Identity
HttpRequest.Current.User.IsAuthenticated
etc.
and retrieve the "custom" created user object that derives from my own
user base class (or one of it's properties). I'd like the consumer to
be able to do this without having to assign anything to
HttpRequest.Current.User themselves, however, I'm struggling with
where any assignment to to the HttpRequest.Current.User should go
within my own membership system's code.
Basically, I'd like to know how the built-in ASP.NET provider model
uses and utilises the IPrincipal interface (and possibly also the
IIdentity interface) so that I can then, hopefully, replicate that
within my own membership system code.
Anyone have advanced knowledge of how all of these things are
implemented and fit together?
Thanks in advance.
Keith.