Providing custom database functionality to custom asp.net membership provider

Posted by IrfanRaza on Stack Overflow See other posts from Stack Overflow or by IrfanRaza
Published on 2010-04-14T09:12:44Z Indexed on 2010/04/14 9:23 UTC
Read the original article Hit count: 219

Hello friends, I am creating custom membership provider for my asp.net application. I have also created a separate class "DBConnect" that provides database functionality such as Executing SQL statement, Executing SPs, Executing SPs or Query and returning SqlDataReader and so on...

I have created instance of DBConnect class within Session_Start of Global.asax and stored to a session. Later using a static class I am providing the database functionality throughout the application using the same single session. In short I am providing a single point for all database operations from any asp.net page.

I know that i can write my own code to connect/disconnect database and execute SPs within from the methods i need to override. Please look at the code below -

public class SGI_MembershipProvider : MembershipProvider {

......

    public override bool ChangePassword(string username, string oldPassword, string newPassword)
    {
        if (!ValidateUser(username, oldPassword))
            return false;

        ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true);

        OnValidatingPassword(args);

        if (args.Cancel)
        {
            if (args.FailureInformation != null)
            {
                throw args.FailureInformation;
            }
            else
            {
                throw new Exception("Change password canceled due to new password validation failure.");
            }
        }

       .....        

//Database connectivity and code execution to change password.

}

....

}

MY PROBLEM - Now what i need is to execute the database part within all these overriden methods from the same database point as described on the top. That is i have to pass the instance of DBConnect existing in the session to this class, so that i can access the methods.

Could anyone provide solution on this. There might be some better techniques i am not aware of that. The approach i am using might be wrong. Your suggessions are always welcome.

Thanks for sharing your valuable time.

© Stack Overflow or respective owner

Related posts about asp.net-membership

Related posts about c#