Reputation: 1200
My project uses the .NET Core (2.2) Angular Spa template. In this setup, the routing is handled by the 'client' Angular (7) web app.
How do I generate the url to the password reset form that will be sent with the password reset email, when there is no controller action related to that route/component?
In a classic ASP.NET project, with Razor pages for example, I would use the UrlHelper class to construct the url that directs to a specific controller and action. Indeed, I still use the UrlHelper to construct an url for the email confirmation message:
var callbackUrl = new Uri(Url.Link("ConfirmEmail", new { username = newUser.UserName, code = code }));
This is possible because there is a Confirm Email action:
[HttpGet, Route("ConfirmEmail", Name = "ConfirmEmail")]
[AllowAnonymous]
public async Task<IActionResult> ConfirmEmail(string username, string code)
{
...
}
The url for the password reset is different because there is no controller action for this. The link contains a code parameter and points to an Angular component. The bit that I cannot find information on is how to get the route/base of the url, which in development is http://localhost:55722
, but in production will be different:
http://localhost:55722/reset-password/my_parameter_here
I could create a 'mock' action that is used to create the url, but this seems to be a hack too far. What is the best way to do this?
Upvotes: 0
Views: 998
Reputation: 7216
If you know where you are serving the Angular app from, generate the URL by hand (also knowing your routing configuration in the Angular app). You can also save the root URL of your angular app in your backend to assist you in the creation of the final URL.
Upvotes: 1