Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys,

I have a problem to use my custom membership provider. My class implements all methods of the MembershipProvider and when I use the WSAT in the security section, I got this message:

"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

The following message may help in diagnosing the problem: "The operation or method is not implemented"

Somebody help me!! How can I fix it???



That's my web.config

XML
<membership defaultprovider="CustomProvider">
      <providers>
        <clear />
        <add name="CustomProvider" type="Owl.CustomMembershipProvider.UserManager" applicationname="TestApp" connectionstringname="QUESTIONNARIESSql" enablepasswordretrieval="false" enablepasswordreset="false" maxinvalidpasswordattempts="5" />
       </providers>
</membership>



That's my CustomMembership Class:

C#
public class UserManager : MembershipProvider
    {
        public UserManager(): base()
        {
 
        }

        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {

            // Inicializar
            base.Initialize(name, config);
        }

        public MembershipUser CreateUser(string email, out MembershipCreateStatus status)
        {
            MembershipUser uInfo = new UserInfo(email, "CustomMembershipProvider", Guid.NewGuid());
            
            try
            {
                using (QuestionnarieEntities context = new QuestionnarieEntities())
                {
                    string auxEmail = (from u in context.UsersData
                                       where u.UserEmail == email
                                       select u.UserEmail).FirstOrDefault();

                    if (auxEmail == null)
                    {
                        UsersData userData = new UsersData();
                        userData.UserEmail = email;
                        userData.UserId = Guid.NewGuid();

                        context.AddToUsersData(userData);
                        context.SaveChanges();
                        status = MembershipCreateStatus.Success;
                        return uInfo;
                    }
                    else
                    {
                        status = MembershipCreateStatus.DuplicateEmail;
                        return uInfo;
                    }
                }

            }
            catch (Exception)
            {
                status = MembershipCreateStatus.UserRejected;
                throw;
            }

        }

        public override bool DeleteUser(string email, bool deleteAllRelatedData)
        {
            try
            {
                // implementar exclusão
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public override MembershipUser GetUser(string email, bool userIsOnline)
        {

            MembershipUser uInfo = new UserInfo(email, "CustomMembershipProvider", Guid.NewGuid()); ; 
            return uInfo;
        }

        public void UpdateUser(UsersData user)
        {

            try
            {
                using (QuestionnarieEntities context = new QuestionnarieEntities())
                {

                    UsersData userData = (from u in context.UsersData
                                          where u.UserEmail == user.UserEmail
                                          select u).FirstOrDefault();

                    userData.UF = user.UF;
                    userData.Age = user.Age;
                    userData.City = user.City;
                    userData.Color = user.Color;
                    userData.Country = user.Country;
                    userData.Gender = user.Gender;
                    userData.Occupation = user.Occupation;
                    userData.Schooling = user.Schooling;

                    context.SaveChanges();
                    
                }

            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool ValidateUser(string email)
        {

            using (QuestionnarieEntities context = new QuestionnarieEntities())
            {
                return true;
                //try
                //{
                //    UsersData userData = (from u in context.UsersData
                //                    where u.UserEmail == email
                //                    select u).FirstOrDefault();

                //    if (userData != null)
                //        return true;
                //    else
                //        throw new Exception("O usuário não foi validado!");
                //}
                //catch (Exception)
                //{
                //    return false;
                //}

            }
        }

        public override string ApplicationName
        {
            get
            {
                return "Authentication";
            }
            set
            {
                string apl= value;
            }
        }



        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            return true;
        }

        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            return true;
        }

        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            status = MembershipCreateStatus.Success;
            MembershipUser user = new UserInfo("sss","CustomProvider",Guid.NewGuid());
            return user;
        }

        public override bool EnablePasswordReset
        {
            get { return false; }
        }

        public override bool EnablePasswordRetrieval
        {
            get { return false; }
        }

        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
             MembershipUserCollection muc = new MembershipUserCollection();
            muc.Add(new UserInfo("sss","CustomProvider",Guid.NewGuid()));
            totalRecords = 1;
            return muc;
        }

        public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection muc = new MembershipUserCollection();
            muc.Add(new UserInfo("sss", "CustomProvider", Guid.NewGuid()));
            totalRecords = 1;
            return muc;
        }

        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection muc = new MembershipUserCollection();
            muc.Add(new UserInfo("sss", "CustomProvider", Guid.NewGuid()));
            totalRecords = 1;
            return muc; ;
        }

        public override int GetNumberOfUsersOnline()
        {
            return 1;
        }

        public override string GetPassword(string username, string answer)
        {
            return "teste";
        }

        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            MembershipUser uInfo = new UserInfo("luizdias@gmail.com", "CustomMembershipProvider", Guid.NewGuid()); ;
            return uInfo;
        }

        public override string GetUserNameByEmail(string email)
        {
            try
            {
                using (QuestionnarieEntities context = new QuestionnarieEntities())
                {
                   string auxEmail = (from u in context.UsersData
                                       where u.UserEmail == email
                                       select u.UserEmail).FirstOrDefault().ToString();

                   return auxEmail;
                    
                }

            }
            catch (Exception)
            {
                return string.Empty;
                throw;
            }            
        }

        public override int MaxInvalidPasswordAttempts
        {
            get { return 3; }
        }

        public override int MinRequiredNonAlphanumericCharacters
        {
            get { return 0; }
        }

        public override int MinRequiredPasswordLength
        {
            get { return 2; }
        }

        public override int PasswordAttemptWindow
        {
            get { return 3; }
        }

        public override MembershipPasswordFormat PasswordFormat
        {
            get { return MembershipPasswordFormat.Clear; }
        }

        public override string PasswordStrengthRegularExpression
        {
            get { return ""; }
        }

        public override bool RequiresQuestionAndAnswer
        {
            get { return false; }
        }

        public override bool RequiresUniqueEmail
        {
            get { return false; }
        }

        public override string ResetPassword(string username, string answer)
        {
            return string.Empty;
        }

        public override bool UnlockUser(string userName)
        {
            return false; // implementei
        }

        public override void UpdateUser(MembershipUser user)
        {
            string s = "s" + "s";
        }

        public override bool ValidateUser(string username, string password)
        {
            return true;
        }
    }
Posted
Updated 17-Jan-13 15:28pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900