我有一個ProfileController端點:
[HttpPut]
[SwaggerOperation("Confirm profile e-mail")]
[Produces("application/json", "application/xml")]
[Route("profile/e-mail")]
[ProducesResponseType(typeof(ExecutionResult), 200)]
public async Task<IActionResult> ConfirmProfileEmail(string token, int userId)
{
//var requestResult = await _mediator.Send(request);
//return this.FromExecutionResult(requestResult);
return Ok(token);
}
同時,我也HttpContextAccessor和LinkGenerator注入我的服務。當我嘗試生成確認鏈接時,我不斷收到null,但不明白我做錯了什么:
var confirmationLink =
_linkGenerator.GetUriByName(
_httpContextAccessor.HttpContext,
"/profile/e-mail",
new { token, userId = newUser.Id });
如果有人可以提供一些說明,我將不勝感激LinkGenerator,因為與該課程相關的檔案并不多,尤其是示例...
uj5u.com熱心網友回復:
GetUriByName需要端點名稱,而不是路由。名稱是路由屬性的一個屬性,例如:[Route("profile/e-mail", Name = "ProfileEmail")]。打電話時,GetUriByName您將傳遞“ProfileEmail”作為名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/374491.html
