忘记密码的方法和放大器;编辑用户的方法不能正常工作 [英] Forgot Password method & Edit User method not working

查看:379
本文介绍了忘记密码的方法和放大器;编辑用户的方法不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建MVC应用4。
 在该申请中


  1. 如果用户忘记了密码,我有方法来发送电子邮件到用户
    重置密码。


  2. 如果管理员想改变用户的当前密码,我的方法来发送电子邮件到相关细节的用户。


所以我得到同样的错误,当我尝试发送电子邮件

我收到错误,如以下


  1. 是我得到了忘记密码的方法错误

<醇开始=2>
  • 是我得到的编辑用户的方法错误

  • 好像我在遇到麻烦时,我尝试发送电子邮件,我使用asp.net成员身份

    这是有关code段忘记口令的方法

      [HttpPost]
                [使用AllowAnonymous]
                [ValidateAntiForgeryToken]
                公共异步任务&LT;&的ActionResult GT; ForgotPassword(ForgotPasswordViewModel模型)
                {            如果(ModelState.IsValid)
                {
                    VAR用户名=等待UserManager.FindByNameAsync(model.UserName);
                    VAR用户=等待UserManager.FindByEmailAsync(model.Email);
                    如果(用户= NULL和放大器;!&安培;!用户名= NULL)
                    {                        VAR提供商=新Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider(my_application之);
                            UserManager.UserTokenProvider =新Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create(\"EmailConfirmation\"));
                            变量code =等待UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                            System.Net.Mail.MailMessage M =新System.Net.Mail.MailMessage(
                            ........

    这是有关code段为编辑用户的方法。

      [HttpPost]
        [CustomAuthorization(IdentityRoles =管理员)]
        [ValidateAntiForgeryToken]
        公共异步任务&LT;&的ActionResult GT; Edit_User(EditUserViewModel editUser)
        {
            尝试
            {
                如果(ModelState.IsValid)
                {
                    AspNetUser用户= db.AspNetUsers.Find(editUser.Id);                如果(editUser.Change ==是){                字符串userid = editUser.Id;
                    字符串NEWPASSWORD = editUser.NewPassword;                VAR提供商=新Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider(my_application之);
                    UserManager.UserTokenProvider =新Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create(\"EmailConfirmation\"));
                    变量code =等待UserManager.GenerateEmailConfirmationTokenAsync(user.Id);                System.Net.Mail.MailMessage M =新System.Net.Mail.MailMessage(
    ................................................

    好像具有同一地点的问题,但无法弄清楚尚未


    解决方案

    我同样的问题,那么很多研究后,我发现,问题出在IIS部署

    所以下面这个线程我能解决我的问题。

    <一个href=\"https://social.msdn.microsoft.com/Forums/vstudio/en-US/ad1f7367-7727-4b1a-a190-840ff4ed5709/adfs-20-sso-the-data-protection-operation-was-unsuccessful?forum=Geneva\"相对=nofollow>数据保护操作不成功


      

        
    1. 打开你的IIS管理器

    2.   
    3. 找到您的应用程序是通过选择你的应用程序,右击它,选择管理应用程序使用的是什么程序池 - >高级
        设置。

    4.   
    5. 之后,在顶部左侧,选择应用程序池,并继续前进,并选择使用你的应用程序的应用程序池。

    6.   
    7. 在右键单击它,选择高级设置,进入流程模型部分,然后找到加载用户配置文件选项并将其设置为
        真实的。

    8.   

    I created MVC 4 application. In that application

    1. If user forgot the password , I have method to send an email to user to reset password.

    2. If Admin want to change user current password ,I have method to send an email to user with relevant details.

    So I'm getting same error when I try to send email

    I'm getting errors like following

    1. Error that I'm getting for Forgot Password method

    1. Error that I'm getting for Edit User method

    Seems like I'm having trouble when I try to send email , I'm using asp.net Identity membership

    This is relevant code snippet for Forgot Password Method

                [HttpPost]
                [AllowAnonymous]
                [ValidateAntiForgeryToken]
                public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
                {
    
                if(ModelState.IsValid)
                {
                    var username = await UserManager.FindByNameAsync(model.UserName);
                    var user = await UserManager.FindByEmailAsync(model.Email);                   
    
    
                    if (user != null && username != null)
                    {
    
                            var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("My_Application");
                            UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create("EmailConfirmation"));          
                            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);                   
    
    
                            System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
                            ........
    

    This is relevant code snippet for Edit User Method

        [HttpPost]
        [CustomAuthorization(IdentityRoles = "Admin")]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Edit_User(EditUserViewModel editUser)
        {    
            try
            {    
                if (ModelState.IsValid)
                {
                    AspNetUser user = db.AspNetUsers.Find(editUser.Id);                                 
    
                    if(editUser.Change == "Yes"){                    
    
                    String userId = editUser.Id;
                    String newPassword = editUser.NewPassword;
    
                    var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("My_Application");
                    UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(provider.Create("EmailConfirmation"));
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
    
                    System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
    ................................................
    

    Seems like having problem in same spot, but couldn't figure it out yet

    解决方案

    I had same issue , then after many research I found out that problem is in IIS deployment

    so following this thread I able to fix my issue

    The data protection operation was unsuccessful

    1. Open your IIS Manager
    2. Find out what AppPool your application is using by selecting your App, right-click on it, and Select Manage Application -> Advanced Settings.
    3. After that, on the top left hand side, select Applications Pools,and go ahead and select the App Pool used by your app.
    4. Right-click on it, and select Advanced Settings, Go to the Process Model Section and Find the "Load User Profile" Option and set it to true.

    这篇关于忘记密码的方法和放大器;编辑用户的方法不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆