当我单击电子邮件验证链接时,我的方法输入中的 activationCode 为空 [英] The activationCode is null in my method input when I click the email Verification link

查看:23
本文介绍了当我单击电子邮件验证链接时,我的方法输入中的 activationCode 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以上帝的名义

大家好.我正在 VS 2017 中为我的 mvc 5 网站创建注册.它有电子邮件确认.用于激活的 URL 链接将在电子邮件中完整接收.当我单击 时,它可以正常工作,并且它恰好通过正确的 ActionMethod 到达我的控制器,但我不知道为什么 activationCode 为空!:|在它正常工作之前,我的意思是激活码不为空.我不知道它发生了什么!

Hi all. I'm creating registration for my mvc 5 website in VS 2017.It has Email confirmation in it. the URL link for activation will be received completely in Email. when I click , it works and it exactly comes to my controller on the correct ActionMethod but I don't know why the activationCode is null! :| While before it worked correctly, I mean the Activation code was not null. I don't know what happend to it!

任何帮助将不胜感激.

 public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
       name: "Password",
       url: "{controller}/{action}/{passwordResetCode}",
       defaults: new { controller = "Authentication", action = "ResetPassword" }
   );
        routes.MapRoute(
       name: "Activation",
       //url: "{controller}/{action}/{activationCode}",
       url: "Authentication/VerifyAccount/{activationCode}", 
       defaults: new { controller = "Authentication", action = "VerifyAccount" }
   );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

推荐答案

你的默认路由接受一个名为 id 的参数,而不是 activationCode.您要么需要将控制器方法更改为

Your default route accepts a parameter named id, not activationCode. You either need to change the controller method to

public ActionResult VerifyTheAccount(string id)

并更改链接以设置 id,例如(来自您的评论)

and change the link to set the id, for example (from your comments)

var verifyURL = "/Authentication/VerifyTheAccount/" + activationCode

或使用首选的 Url.Action() 方法

var verifyURL = '@Url.Action("VerifyTheAccount", "Authentication", new { id = activationCode })

或者,您需要在 DefaultRoute

routes.MapRoute(
   name: "Activation",
   url: "Authentication/VerifyTheAccount/{activationCode}",
   defaults: new { controller = "Authentication", action = "VerifyTheAccount" }
);

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

这篇关于当我单击电子邮件验证链接时,我的方法输入中的 activationCode 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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