Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a callback URL to Identity/Pages/Account/ConfirmEmail from a controller?

I've got a scenario where I want to generate an email confirmation URL the same way as in the Register page of the Identity area ("Identity/Pages/Account/Register"). I've already scaffolded the Identity area and have access to its Pages.

I need this to happen from a controller located in a completely different area. I try to do something similar as in Register.cshtml.cs but instead of using Url.Page I use Url.Action (we're located inside a controller remember).

The problem is that the following code generates a null string which is not exactly what we are after:

string confirmationLink = Url.Action("ConfirmEmail",
                        "Account", new
                        {
                            area = "Identity",
                            userid = viewModel.User.Id,
                            token = code
                        },
                        protocol: HttpContext.Request.Scheme);

What am I possibly doing wrong here? This is located in

/Areas/CompanyUsers/Controllers/HomeController.cs.

Please refrain from commenting on the idea of generating this url from a "random" controller. I need a way of registering users from an already authenticated user (A company owner user must have the ability to register users into the application without them needing to use the default Identity way of doing this.).

like image 499
Stoyan Lupov Avatar asked Oct 31 '25 05:10

Stoyan Lupov


1 Answers

Url.Action is for generating URLs for actions, but ConfirmEmail is a page. Use Url.Page to generate the correct URL:

string confirmationLink = Url.Page(
    "/Account/ConfirmEmail",
    null, // handler
    new { area = "Identity", userid = viewModel.User.Id, token = code },
    Request.Scheme);
like image 185
Kirk Larkin Avatar answered Nov 02 '25 21:11

Kirk Larkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!