我在 ASP.NET Core 2.2 MVC 项目中的 EmailSender 服务中使用 LinkGenerator。它首先返回 Null 值,直到我发现我需要在定义中包含该区域。但是,Url 仍然没有提供我期望的服务器信息。
它生成的 URL 如下所示: "/Identity/Account/Login...“
我期待这个: "https://{hostName}/Identity/Account/Login..."
我的解决方法是将 httpContextAccessor 中发布的值连接起来。但是,这似乎是假的。有人可以给我指示这应该如何工作吗?
解决(不是很好):
var callbackUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://" +
$"{httpContextAccessor.HttpContext.Request.Host}" +
linkGenerator.GetPathByPage(httpContextAccessor.HttpContext,
"/Account/Login", null, new {area = "Identity", userId = user.Id});
Run Code Online (Sandbox Code Playgroud)