【问题标题】:Password recovery not sending email.密码恢复不发送电子邮件。
【发布时间】:2012-07-07 13:30:09
【问题描述】:

我有一个在 LoginView 内构建的超链接,文本设置为“忘记密码”。

点击超链接后,会弹出密码恢复控件(通过 AJAX ModalPopUp 扩展器的实现)。modalpopup 运行良好。但问题是,在输入用户名后,在第 2 步中用户回答了他/她的安全答案后,当点击“提交”按钮时,它不会进入第 3 步,也没有发送电子邮件。

但是,数据库中的密码已更改(我尝试使用用户名和旧密码登录,但没有成功)。

这里是 passwordrecover.aspx 的代码:

<asp:HyperLink ID="HyperLink2" runat="server" 
             style="margin-top:15px; text-align: right;">Forget Password</asp:HyperLink>

                        <asp:ModalPopupExtender 
                        ID="HyperLink2_ModalPopupExtender" 
                        runat="server" 
                        BackgroundCssClass="modalBackground" 
                        DynamicServicePath="" 
                        Enabled="True" 
                        PopupControlID="Panel1" 
                        TargetControlID="HyperLink2" >

                        </asp:ModalPopupExtender>

                        <asp:Panel ID="Panel1" 
                        runat="server" 
                        BackColor="White" 
                        BorderColor="Black" 
                        BorderStyle="Solid" 
                        BorderWidth="2px" 
                        Height="200px" 
                        Width="360px">

                         <asp:UpdatePanel ID="UpdatePanel1" runat="server">

                         <ContentTemplate>

                  <asp:PasswordRecovery ID="PasswordRecovery1" runat="server"
                    onsendingmail="PasswordRecovery1_SendingMail"> 

                <MailDefinition BodyFileName="~/EmailTemplates/ResetPassword.htm" 
                    From="bedofrosesptltd@gmail.com" IsBodyHtml="True" Priority="High" 
                    Subject="Request on the password reset for BedOfRoses's account.">
                </MailDefinition>

                </asp:PasswordRecovery>


                              </ContentTemplate>
                            </asp:UpdatePanel>

                            <asp:Button ID="btnClose" runat="server" Text="Close" />
                        </asp:Panel>

下面是代码:

 protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
    {
        System.Web.UI.WebControls.PasswordRecovery PasswordRecovery1 = (System.Web.UI.WebControls.PasswordRecovery)LoginView1.FindControl("PasswordRecovery1");
            MembershipUser pwRecover = Membership.GetUser(PasswordRecovery1.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 = "/Members/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);
        }
  • 如果我从 ModalPopUp 中删除密码恢复控件,整个控件将完美运行。只有当它在 ModalPopUp 中构建时,它才能进行最后一步并且没有发送电子邮件。然而,当他/她的用户名和旧密码时,用户无法登录。

【问题讨论】:

    标签: c# asp.net ajax forgot-password password-recovery


    【解决方案1】:

    最可能的原因可能是当您的表单在模型弹出窗口中打开时,表单(即密码恢复表单)不再保留在 FORM 标记中。所以你需要做一些类似于

    jQuery(function() {
       var dlg = jQuery("#dialog").dialog({ 
                            draggable: true, 
                            resizable: true, 
                            show: 'Transfer', 
                            hide: 'Transfer', 
                            width: 320, 
                            autoOpen: false, 
                            minHeight: 10, 
                            minwidth: 10 
              });
      dlg.parent().appendTo(jQuery("form:first"));
    });
    

    它在 FORM DOM 中移动 Popup。当您的表单不在 FORM DOM 中时,它的数据将不会被发送回服务器。

    参考:jQuery UI Dialog with ASP.NET button postback

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 2010-11-05
      • 1970-01-01
      • 2011-10-07
      • 2013-12-18
      • 2015-08-13
      • 1970-01-01
      相关资源
      最近更新 更多