Source Error:
Line 55: MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
Line 56:
Line 57: Object UserGUID= User.ProviderUserKey; //error appeared here
Line 58:
Line 59: DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
我在 createuserwizard 中有一个额外的步骤,在完成表单后,它会将用户信息存储在数据库中。但是发生了这个错误:
Object reference not set to an instance of an object.
我还为链接 55、57、59 设置了一个断点。从第 57 行开始,用户为空,他们无法从数据库中获取用户。
后面的代码:
protected void CreateUserWizard1_CreatedUser(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
MSCaptcha.CaptchaControl Captcha1 = (CreateUserWizardStep1.ContentTemplateContainer.FindControl("Captcha1") as MSCaptcha.CaptchaControl);
TextBox txtCaptcha = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCaptcha");
Label Captchalbl = (Label)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Captchalbl");
Response.Write(txtCaptcha.Text);
Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
if (!Captcha1.UserValidated)
{
Captchalbl.Text = "InValid";
e.Cancel = true;
}
else
{
Captchalbl.Text = "Valid";
TextBox UserNameTextBox =
(TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
SqlDataSource DataSource =
(SqlDataSource)CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo");
MembershipUser User = Membership.GetUser(UserNameTextBox.Text);
Object UserGUID= User.ProviderUserKey; //here is link 57.
DataSource.InsertParameters.Add("UserId", UserGUID.ToString());
DataSource.Insert();
}
}