我有一个场景,我想以与身份区域(“身份/页面/帐户/注册”)的注册页面相同的方式生成电子邮件确认 URL。我已经搭建了标识区域并可以访问其页面。
我需要从位于完全不同区域的 Controller 发生这种情况。 我尝试做一些与 Register.cshtml.cs 中类似的事情,但我没有使用 Url.Page,而是使用 Url.Action(我们位于 Controller 内部,请记住)。
问题是下面的代码生成了一个空字符串,这不是我们想要的:
string confirmationLink = Url.Action("ConfirmEmail",
"Account", new
{
area = "Identity",
userid = viewModel.User.Id,
token = code
},
protocol: HttpContext.Request.Scheme);
我在这里可能做错了什么?这位于
/Areas/CompanyUsers/Controllers/HomeController.cs.
请不要评论从“随机” Controller 生成此 url 的想法。我需要一种从已经通过身份验证的用户注册用户的方法(公司所有者用户必须能够将用户注册到应用程序中,而无需使用默认身份方式来执行此操作。)。
最佳答案
Url.Action
用于为操作 生成 URL,但 ConfirmEmail
是一个页面。使用 Url.Page
生成正确的 URL:
string confirmationLink = Url.Page(
"/Account/ConfirmEmail",
null, // handler
new { area = "Identity", userid = viewModel.User.Id, token = code },
Request.Scheme);
关于c# - 如何从 Controller 获取到 Identity/Pages/Account/ConfirmEmail 的回调 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57224065/