ASP.NET Membership Email Verification

亡梦爱人 提交于 2019-12-03 08:31:54

I finally got this to work.

  1. onsendingmail="CreateUserWizard1_SendingMail" This should be in create user wizard.

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" onsendingmail="CreateUserWizard1_SendingMail">
    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" DisableCreatedUser="True">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" />
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" />
        </WizardSteps>
        <MailDefinition BodyFileName="NewAccountTemplate.htm" From="example@example.com" IsBodyHtml="True"  Subject="Steps to activate your new account..." Priority="High" />
    </asp:CreateUserWizard>
    

  2. use just <%VerificationUrl%> in NewAccountTemplate.htm

  3. Change registration.aspx.cs to

    // Get the UserId of the just-added user
    MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName);
    Guid newUserId = (Guid)newUser.ProviderUserKey;
    
    // Determine the full verification URL (i.e., http://yoursite.com/Verification.aspx?ID=...)
    string urlBase = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
    string verifyUrl = "Verify.aspx?ID=" + newUserId.ToString();
    string fullUrl = urlBase + verifyUrl;
    
    // Replace <%VerificationUrl%> with the appropriate URL and querystring
    e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", fullUrl);
    
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!