【发布时间】:2022-01-13 11:40:27
【问题描述】:
在另一个 ASP.NET MVC 5 控制器项目中,AccountController 继承自 Controller 类。在这个类中,当我尝试生成一个 URL 来重置用户密码时,我有以下实现。
// Send an email with this link
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
但是,我将我的逻辑移到了一个 Web API 项目,其中 AccountController 从 ApiController 类中插入。为了生成 URL 以重置用户密码,我有以下实现:
var _url = new System.Web.Mvc.UrlHelper();
var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = _url.Action("ResetPassword", "Account", new { UserId = user.Id, code = code }, Request.RequestUri.Scheme);
有了这个后来的实现,AccountController : ApiController,我得到一个错误:
"ExceptionMessage": "值不能为空。
参数名称:routeCollection"
我错过了什么?
【问题讨论】:
标签: asp.net-mvc asp.net-web-api asp.net-identity