The activationCode is null in my method input when I click the email Verification link

核能气质少年 提交于 2019-12-01 14:32:40

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

public ActionResult VerifyTheAccount(string id)

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

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

or using the preferred Url.Action() method

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

Alternatively you need to create a specific route definition before the 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 }
);

In order to achieve what you need you have to change the action parameter name to id or you can add extra route to your RouteConfig as following:

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

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

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

    }

Note that the order of routes definition is very important.

Now when running the application you will get the following results:

And inside the browser:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!