ASP WebForms注册确认

时间:2018-01-02 20:44:56

标签: asp.net asp.net-identity owin

当我向我的网站注册新用户时,代码应该为用户生成一封电子邮件然后确认,但是没有发送电子邮件。请帮忙

using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using WebAppForms.Models;

namespace WebAppForms.Account
{
public partial class Register : Page
{
    protected void CreateUser_Click(object sender, EventArgs e)
    {
        var manager = 
Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
        var signInManager = 
Context.GetOwinContext().Get<ApplicationSignInManager>();
        var user = new ApplicationUser() { UserName = Email.Text, Email = 
Email.Text };
        IdentityResult result = manager.Create(user, Password.Text);
        if (result.Succeeded)
        {

            string code = manager.GenerateEmailConfirmationToken(user.Id);
            string callbackUrl = 
IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
            manager.SendEmail(user.Id, "Confirm your account", "Please 
confirm your account by clicking <a href=\"" + callbackUrl + 
"\">here</a>.");

            signInManager.SignIn( user, isPersistent: false, 
rememberBrowser: false);

IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], 
Response);
        }
        else 
        {
            ErrorMessage.Text = result.Errors.FirstOrDefault();
        }
    }
}
}

我遵循了Microsoft教程,但它仍然无法正常工作

0 个答案:

没有答案