我的网络表单中有一个密码恢复控件。输入所有必要的详细信息后,将向用户的电子邮件帐户发送一封电子邮件。
这就像 - 如果用户忘记了他/她的密码,则向用户的电子邮件帐户发送密码更改链接而不是新密码。
但是,单击提交按钮后,“对象引用未设置为对象的实例”。出现错误。
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. And the error occurred on line 66.
Source Error:
Line 64: System.Web.UI.WebControls.Login Login1 = (System.Web.UI.WebControls.Login)LoginView1.FindControl("Login1");
Line 65: MembershipUser pwRecover = Membership.GetUser(Login1.UserName);
**Line 66: Guid userInfoId2 = (Guid)pwRecover.ProviderUserKey;**
以下是消息正文中发送 url 的后台代码:
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
System.Web.UI.WebControls.Login Login1 = (System.Web.UI.WebControls.Login)LoginView1.FindControl("Login1");
MembershipUser pwRecover = Membership.GetUser(Login1.UserName);
Guid userInfoId2 = (Guid)pwRecover.ProviderUserKey;
//Create an url that will link to a UserProfile.aspx and
//accept a query string that is the user's id
//setup the base of the url
string domainName = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
//setup the second half of the url
string confirmationPage = "/UserProfile.aspx?ID=" + userInfoId2.ToString();
//combine to make the final url
string url = domainName + confirmationPage;
// Replace <%VerifyUrl%> placeholder with url value
e.Message.Body = e.Message.Body.Replace("<%ResetPassword%>", url);
}