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

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

问题描述

奉上帝之名

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

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为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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