Overriding MembershipProvider and RoleProvider Initialize method

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
JORGEMAL
Posts: 165
Joined: Thu 03 Jul 2008 23:55

Overriding MembershipProvider and RoleProvider Initialize method

Post by JORGEMAL » Wed 07 Jan 2015 02:49

I am overriding the Initialize method of PgSqlMembershipProvider and PgSqlRoleProvider because our web application connects to different databases with the same schema. For this, I have 2 classes that inherit from PgSqlMembershipProvider and from PgSqlRoleProvider. How does the Initialize method work? When is it executed? How can I execute it on-demand so I can re-define the connection string in order to modify the database?

In the code below, the method "Utilerias.ObtenerConnString" returns a new connection string which includes a database depending on a certain criteria.

Code: Select all

public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
    {
        String strConn = Utilerias.ObtenerConnString();
        base.Initialize(name, config);
        base.connectionString = strConn;
    }
Respectfully,
Jorge Maldonado

Shalex
Devart Team
Posts: 8033
Joined: Thu 14 Aug 2008 12:44

Re: Overriding MembershipProvider and RoleProvider Initialize method

Post by Shalex » Wed 14 Jan 2015 15:41

JORGEMAL wrote:How does the Initialize method work?
Here is a description of the Initialize method: http://msdn.microsoft.com/en-us/library ... .110).aspx.
JORGEMAL wrote:When is it executed?
Our code only overrides this method from a base class. Please use some decompiler (e.g.: ILSpy) to find points in Microsoft assembly where it is invoked.
JORGEMAL wrote:How can I execute it on-demand so I can re-define the connection string in order to modify the database?
This method is public. You can call it like any other public method.

JORGEMAL
Posts: 165
Joined: Thu 03 Jul 2008 23:55

Re: Overriding MembershipProvider and RoleProvider Initialize method

Post by JORGEMAL » Wed 14 Jan 2015 16:36

Thanks for your reply.
Because I want to connect to several databases (all of them with exactly the same schema) from my web application (depending upon the business I want to manage), every DB has its own set of roles and login roles. From this, I understand that I need to re-initialize the PgSqlMembershipProvider and PgSqlRoleProvider definition (DB connection string for example) in order to get access to membership tables of other business that we maintain. This issue requires me to re-Initialize both providers (membership and role).

Is my approach correct? I want to make sure I am taking the right direction.

Respectfully,
Jorge Maldonado

Shalex
Devart Team
Posts: 8033
Joined: Thu 14 Aug 2008 12:44

Re: Overriding MembershipProvider and RoleProvider Initialize method

Post by Shalex » Mon 19 Jan 2015 11:20

We do not have much experience of implementing such (or similar) approach so we cannot give a piece of advice to you. This question exceeds the goals of our support.

Post Reply