Search code examples
asp.net-membershipmembership-providerroleprovider

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


Solution

  • 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.