I have got a ProfileController
with the endpoint:
[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);
}
Meanwhile, I have HttpContextAccessor
and LinkGenerator
injected into my service. When I try to generate the confirmation link, I keep getting null
, but don't understand what do I do wrong:
var confirmationLink =
_linkGenerator.GetUriByName(
_httpContextAccessor.HttpContext,
"/profile/e-mail",
new { token, userId = newUser.Id });
I would really appreciate if someone could give some clarificaton to working with LinkGenerator
, as there is not so much documentation related to this class, especially with examples...
CodePudding user response:
GetUriByName
requires the endpoint name, not the route. The name being a property of the route attribute, for example: [Route("profile/e-mail", Name = "ProfileEmail")]
. When calling GetUriByName
you would pass "ProfileEmail" as the name.