Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC5电子邮件确认_C#_Asp.net_Email_Asp.net Mvc 5 - Fatal编程技术网

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;
}