i have the folowing code in activation page after the user activate the account with email link. i am getting "object reference not set to an instance of an object" error for the line " newUser.IsApproved = true;". i check userId string and it gets the user Id string and the string is not empty.Membership.Getuser() always gets null , anyone can help me?
//request for signed user UserId
Guid activationCode = new Guid(Request.QueryString["ActivationCode"]);
string userId = "";
string ConnectionString = ConfigurationManager.AppSettings["myConnectionString"];
try
{
using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
{
SqlCommand sqlCommand = new SqlCommand("SELECT user_id FROM ActivationCode WHERE activation_code LIKE '%" + activationCode + "%'", sqlConnection);
sqlConnection.Open();
SqlDataReader userIdRdr;
userIdRdr = sqlCommand.ExecuteReader();
while (userIdRdr.Read())
{
userId = userIdRdr["user_id"].ToString();
}
sqlConnection.Close();
MembershipUser newUser = Membership.GetUser(userId);
//activate signed user
newUser.IsApproved = true;
Membership.UpdateUser(newUser);
}
}
got it!!!