2017-03-02 23 views
0

ユーザーにパスワードリセットを許可しようとしていますが、なぜcodecallbackUrlがfalseを返すのかわかりません。両方の値が、それは誤りないIUserTokenProviderを生成し、nullを返すのでIUserTokenProviderが登録されていないというエラーが発生するのはなぜですか?

[HttpPost] 
[AllowAnonymous] 
[ValidateAntiForgeryToken] 
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model) 
{ 
    if (ModelState.IsValid) 
    { 
     var user = await UserManager.FindByNameAsync(model.Email); 
     if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) 
     { 
      // Don't reveal that the user does not exist or is not confirmed 
      return View("ForgotPasswordConfirmation"); 
     } 

     // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 
     // Send an email with this link 
     string callbackUrl = await ResetPasswordConfirmationTokenAsync(user.Id, "Password Reset"); 
     return RedirectToAction("ForgotPasswordConfirmation", "Account"); 
    } 

    // If we got this far, something failed, redisplay form 
    return View(model); 
} 

see breakpoint info

が、私は、パスワードのリセットタスク

private async Task<string> ResetPasswordConfirmationTokenAsync(string userID, string subject) 
{ 
    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 
    // Send an email with this link: 
    string code = await UserManager.GeneratePasswordResetTokenAsync(userID); 
    var callbackUrl = Url.Action("ForgotPassword", "Account", new { userId = userID, code = code }, protocol: Request.Url.Scheme); 
    await UserManager.SendEmailAsync(userID, subject, "Please confirm your account by <a href=\"" + callbackUrl + "\">clicking here</a>"); 


    return callbackUrl; 
} 

see breakpoint info for this

を作成します。ここに私のパスワードを忘れた方法であります登録されています。userがnullでない場合、なぜこのようなことが起こりますか?

+0

タイトルがより具体的に変更されるまで、投票を中止します。 –

+0

可能な複製 http:// stackoverflow。com/questions/22629936/no-iusertokenprovider-is-registered – PAVITRA

答えて

0

私はまったく同じ問題を抱えていました。メールサービスクラスをまだ作成していない場合は、そのクラスを再設定する必要があります。

public async Task SendAsync(IdentityMessage message) 
{ 
    MailMessage email = new MailMessage(new 
    MailAddress("[email protected]", "(any subject here)"), 
    new MailAddress(message.Destination)); 
    email.Subject = message.Subject; 
    email.Body = message.Body; 

    email.IsBodyHtml = true; 

    GmailEmailService mailClient = new GmailEmailService(); 
    await mailClient.SendMailAsync(email); 
} 

次に、最後にアカウントコントローラに追加する必要があるいくつかの変更がある

<appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 

    <add key="GmailUserName" value="[email protected]"/> 
    <add key="GmailPassword" value="yourPassword"/> 
    <add key="GmailHost" value="yourServer"/> 
    <add key="GmailPort" value="yourPort"/> 
    <add key="GmailSsl" value="chooseTrueOrFalse"/>  
</appSettings> 

のWebConfigに資格情報を追加します。私はあなたがこのようなものを使用することをお勧め。以下を参照してください:


  1. MyClassesを指しますと呼ばれる新しいフォルダを作成し、次のクラスを作成し、追加

    public class GmailEmailService:SmtpClient 
    { 
        // Gmail user-name 
        public string UserName { get; set; } 
    
    
    public GmailEmailService() : 
        base(ConfigurationManager.AppSettings["GmailHost"], Int32.Parse(ConfigurationManager.AppSettings["GmailPort"])) 
    { 
        //Get values from web.config file: 
        this.UserName = ConfigurationManager.AppSettings["GmailUserName"]; 
        this.EnableSsl = Boolean.Parse(ConfigurationManager.AppSettings["GmailSsl"]); 
        this.UseDefaultCredentials = false; 
        this.Credentials = new System.Net.NetworkCredential(this.UserName, ConfigurationManager.AppSettings["GmailPassword"]); 
    } 
    
    }
  2. はあなたのアイデンティティクラス

    public async Task SendAsync(IdentityMessage message) 
    { 
        MailMessage email = new MailMessage(new MailAddress("[email protected]", "(any subject here)"), 
        new MailAddress(message.Destination)); 
        email.Subject = message.Subject; 
        email.Body = message.Body; 
    
    
    email.IsBodyHtml = true; 
    
    GmailEmailService mailClient = new GmailEmailService(); 
    await mailClient.SendMailAsync(email); 
    
    }を設定します
  3. web.configに資格情報を追加します。この部分でGmailを使用しなかったのは、Gmailの使用が私の職場でブロックされており、それでも完全に機能しているからです。

    <add key="GmailUserName" value="[email protected]"/> 
    <add key="GmailPassword" value="yourPassword"/> 
    <add key="GmailHost" value="yourServer"/> 
    <add key="GmailPort" value="yourPort"/> 
    <add key="GmailSsl" value="chooseTrueOrFalse"/> 
    <!--Smptp Server (confirmations emails)--> 
    

  4. あなたのアカウント・コントローラに必要な変更を行います。次の強調表示されたコードを追加します。

First do this

Then This

実行しコンパイルします。乾杯!

+0

ソリューションへのリンクは歓迎しますが、あなたの答えがそれなしで役に立つことを確認してください:[リンクの前後にコンテキストを追加](// meta.stackexchange.com/a/ 8259)ので、あなたの仲間のユーザーは、それが何であるか、なぜそれがあるのか​​を知り、ターゲットページが利用できない場合にリンクしているページの最も関連性の高い部分を引用します。 [リンクよりもほんの少しの回答は削除されるかもしれません。](// stackoverflow.com/help/deleted-answers) – NobodyNada

+0

私は近くにいました。あなたがアカウントコントローラで指摘した 'DpapiDataProtectionProvider'ビットがありませんでした。ありがとう! – user6225

+0

@NobodyNada、それは良いですか? – Skullomania

関連する問題