user338195
user338195

Reputation:

Is it necessary to override the membership and the role providers?

I'm working on a web app and I don't want to store the connection strings in the web or app config because of the requirements.

So far I have found the only way to achieve this - to override the membership and the role providers.

I also don't fully understand why do I also have to override a role provider when all authentication is apparantely handled by the membership provider?

Thank you

Upvotes: 0

Views: 183

Answers (2)

user338195
user338195

Reputation:

I have found a solution online, which is a bit of a hack, but saves me from overriding membership and role providers.

Solution is to set a connection string in global.asax through reflection:

protected void Application_PreRequestHandlerExecute()
{
    try
    {
        SetProviderConnectionString(DllForConnectionStringManagement.GetConnectionString());
    }
    catch (Exception e)
    {
    // Log and throw
    }
}

SetProviderCOnnectionString is a private method which sets the connections of membership and role provider through reflection.

Upvotes: 0

Sky Sanders
Sky Sanders

Reputation: 37104

While the SqlRoleProvider and SqlMembershipProvider are separate concerns, they both talk to the same database (typically).

They each have a distinct configuration section and require an instance of a connections string.

I approve of the strategy you discovered on the other question and if you wish to use roles you will have to do the same thing, configuration in code, as you are doing for membership.

You should link to the other question to give context and prevent getting flagged as a duplicate.

Upvotes: 1

Related Questions