Url.Action 返回 null

Chi*_*ief 0 c# razor asp.net-core

我正在尝试使用 asp.net core 3 构建电子邮件确认链接。生成令牌后,使用此代码生成确认电子邮件链接始终返回 null。

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
            var confirmationLink = Url.Action(
                "ConfirmEmail",
                "Users",
                new { userId = user.Id, token }, protocol: Request.Scheme
                );
Run Code Online (Sandbox Code Playgroud)

这是一个 .net core 3 Web api 项目,没有 mvc。在启动时配置是使用:app.UseRouting()。

上面我可能做错了什么以及为什么它总是返回 null。我需要什么来满足该方法才能返回正确的期望值?

Fei*_*Han 5

尝试使用asp.net core 3构建电子邮件确认链接。生成令牌后,使用此代码生成confirmEmail链接始终返回null。

本文档中,您可以找到:

Generating a URI for an invalid route (a controller/action or page that doesn't 

exist) will produce an empty string under endpoint routing instead of producing 

an invalid URI.
Run Code Online (Sandbox Code Playgroud)