【问题标题】:how can i send clickable link to user via sms in mvc如何通过 mvc 中的短信向用户发送可点击的链接
【发布时间】:2015-07-16 07:24:56
【问题描述】:

您好,我正在尝试通过短信向用户发送重置密码链接,就像您使用 mvc 中的电子邮件密码重置发送它一样

我现在拥有 ryt 的代码只是向我发送了一条带有完整 url 和用户 ID 的短信,而不是我可以点击的部分

这是我的电子邮件代码重置,首先显示我如何重置

   [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
    {
        //SendSmsBusiness objap = new SendSmsBusiness();
        RegisterBusiness reg = new RegisterBusiness();
        EmailBusiness _emailBusiness = new EmailBusiness();
        if (ModelState.IsValid)
        {

            ApplicationUser user = new ApplicationUser();
            user = reg.UserManager.FindByEmail(model.Email);

            // 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
            if (user != null)
            {
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol:Request.Url.Scheme);
                await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                _emailBusiness.SendEmailForgot(model.Email, callbackUrl);
                return RedirectToAction("ForgotPasswordConfirmation", "Account");
            }

            {
                ModelState.AddModelError("", "The user does not exist");
                return View();
            }
        }
        // If we got this far, something failed, redisplay form
        return View(model);
    }

这很有效

这是我的短信重置代码

   // GET: /Account/ForgotPassword
    [AllowAnonymous]
    public ActionResult PhoneReset()
    {
        return View();
    }
    // POST: /Account/ForgotPassword
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> PhoneReset(ForgotPasswordView model,string sms)
    {
        RegisterBusiness reg = new RegisterBusiness();

        if (ModelState.IsValid)
        {
            ApplicationUser user = new ApplicationUser();
            user = reg.UserManager.FindByEmail(model.Email);
            // 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
            if (user != null)
            {
                //string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                SendSmsBusiness objap = new SendSmsBusiness();

                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                sms =  "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>";
                objap.Send_SMS(model.Phone, sms);
                await SignInAsync(user, isPersistent: false);
                return RedirectToAction("ResetViaPhone", "Account");
            }
            else if (user == null)
            {
                ModelState.AddModelError("", "The user does not exist");
                return View();
            }
        }
        // If we got this far, something failed, redisplay form
        return View(model);
    }

在短信中我收到了这个 - 请点击重置您的密码

但是没有链接。 minenhle@gmail.com 是我用来重置密码的。

我不知道我在哪里弄错了,或者我尝试什么是不可能的

【问题讨论】:

    标签: c# asp.net-mvc asp.net-identity-2


    【解决方案1】:

    SMS 消息不是 HTML,因此它们不理解锚标记。大多数设备都会使看起来像 URL 的东西可以点击,但这取决于您要发送到的设备。此外,Url.Action 会生成一个相对 URL,因为它不在页面上,您需要创建一个完全限定的 URL。

    sms =  "Please reset your password by clicking " + callbackUrl;
    

    【讨论】:

    【解决方案2】:
    <a href="sms:recepient Phone #;?&body=My Name is- %20Kamlesh%20Gathe">
         Click here to text me
    /a>
    

    %20 用于提供空间。

    此链接可以嵌入到任何地方的电子邮件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-09
      • 2013-04-24
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      相关资源
      最近更新 更多