C# MVC5电子邮件确认
我一直在看各种教程,发现其中一个乍看起来很理想,但是我在实现中遇到了一些问题。有人能帮我解决以下问题吗C# MVC5电子邮件确认,c#,asp.net,email,asp.net-mvc-5,C#,Asp.net,Email,Asp.net Mvc 5,我一直在看各种教程,发现其中一个乍看起来很理想,但是我在实现中遇到了一些问题。有人能帮我解决以下问题吗 public class ApplicationUser : IdentityUser { public Nullable<int> TitleId { get; set; } public Nullable<int> SexId { get; set; } public string Forename { get; set; } pub
public class ApplicationUser : IdentityUser
{
public Nullable<int> TitleId { get; set; }
public Nullable<int> SexId { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string ConfirmationToken { get; set; }
public Nullable<bool> Active { get; set; }
public DateTime? JoinDate { get; set; }
}
在Visual Studio 2013中,单词ShortGuid
以红色下划线,因此我猜我缺少了一个名称空间或类
private void SendEmailConfirmation(string to, string username, string confirmationToken)
{
dynamic email = new Email("RegEmail");
email.To = to;
email.UserName = username;
email.ConfirmationToken = confirmationToken;
email.Send();
}
行中动态电子邮件=新电子邮件(“RegEmail”)代码>单词电子邮件
以红色下划线。也可以修改为使用smtp.yahoo.com,端口587使用NetworkCredential和EnableSsl
private bool ConfirmAccount(string confirmationToken)
{
ApplicationDbContext context = new ApplicationDbContext();
ApplicationUser user = context.Users.SingleOrDefault(u => u.ConfirmationToken == confirmationToken);
if (user != null)
{
user.Active = true;
DbSet<ApplicationUser> dbSet = context.Set<ApplicationUser>();
dbSet.Attach(user);
context.Entry(user).State = EntityState.Modified;
context.SaveChanges();
return true;
}
return false;
}
private bool confirmationAccount(字符串确认令牌)
{
ApplicationDbContext上下文=新的ApplicationDbContext();
ApplicationUser user=context.Users.SingleOrDefault(u=>u.ConfirmationToken==ConfirmationToken);
如果(用户!=null)
{
user.Active=true;
DbSet)
任何帮助都将不胜感激。希望我不会太晚;)
我在同一个博客上遇到了完全相同的问题。
您必须按照Andreas评论中的说明安装更多软件包。
在包管理器控制台中运行此命令:
安装邮政包-版本0.9.2
这将使您能够解析带有“邮政”引用的电子邮件
此外,如果您将return语句替换为:
返回ShortGuid.NewShortGuid();
我没有使用您的其余代码,但我想您也可以使用更多的软件包安装来解决这些问题;)只是为了让您开始使用ShortGuid,它不是基类的一部分,因此您需要依赖于库。谢谢,我已经安装了软件包ShortGuid 1.0.0,现在单词ShortGuid
不再是下划线红色为ed,但单词NewGuid
为。
private bool ConfirmAccount(string confirmationToken)
{
ApplicationDbContext context = new ApplicationDbContext();
ApplicationUser user = context.Users.SingleOrDefault(u => u.ConfirmationToken == confirmationToken);
if (user != null)
{
user.Active = true;
DbSet<ApplicationUser> dbSet = context.Set<ApplicationUser>();
dbSet.Attach(user);
context.Entry(user).State = EntityState.Modified;
context.SaveChanges();
return true;
}
return false;
}