0
我在激活頁面中有以下代碼,用戶通過電子郵件鏈接激活帳戶。我得到了「newUser.IsApproved = true;」這一行錯誤的「對象引用未設置爲對象的實例」錯誤。 我檢查userId字符串,它得到用戶Id字符串和字符串不empty.Membership.Getuser()總是得到空,任何人都可以幫助我?C#asp.net Membership.Getuser()總是爲空
//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);
}
}
您使用什麼會員服務?你能爲此顯示配置嗎? –
我正在使用默認的。 – user3719173
您確定會員資格配置正確嗎?我的意思是其他網頁正常工作? – Alireza