The following code builds a clickable URL which is emailed to user:
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { userId = response.Id, code = response.EmailConfirmationCode, returnUrl = returnUrl },
protocol: Request.Scheme);
All the params / values show up in the clickable URL in the email. However, when the user clicks the URL, the page model Get method only gets the first userId param:
public async Task<IActionResult> OnGetAsync(string userId, string code, string returnUrl)
{
//
}
I have tried public async Task<IActionResult> OnGetAsync([FromQuery] string userId, [FromQuery] string code, [FromQuery] string returnUrl) but to no avail.
HttpContext.Request.Query is empty too.
What do I miss?
Your generated URL is getting HTML-encoded at some point in the process and the query string
&separators are converted to their equivalent HTML entity (&). This is fine if you want to display the query string in an HTML page, but not if you want to read the query string.If you are using Razor at any point to generate the HTML email, use
Html.Raw()on the URL to prevent it from being encoded.You should find that
https://iam.mydomain.com/Account/ConfirmEmail?userId=<GUID>&code=<very long string>&returnUrl=%2F_Hostworks as expected.