'Confirmation link in email has been sent, but how do I test the link?
I have an MVC (C#) application where I'm in the middle of testing confirmation email loops. When someone registers on my application, an email is sent to me so I can approve their account. My application successfully sends the email to me with a link, when I click the link in the email it also successfully sends an email to the registrant that I have approved their account. What I can't see is the actual confirmation page that should come up when I click the link in the email, I get a "Site can't be reached" error. How do you test these types of loops with an unpublished project?
The code that formats the link sent to me:
"Body = <h1>New User: " + model.Email.ToString() + "</h1><p><a href=\"" + Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + "/Account/ConfirmRegistration?id=" + user.Id.ToString() + "\" >Confirm Registration</a></p>"
The resulting link looks similar to this https://localhost/Account/ConfirmRegistration?id=guid-goes-here. Seems all I would need to do is add a port number on the end of localhost but I'm unsure what that number would be. 80 and 443 don't work.
Solution 1:[1]
You might be looking for Request.Url.Host. If the host and port are http + 80 or https + 443, you don't need to include them.
I would recommend you manually specify the host in appsettings.json, rather than trying to work it out at runtime. There are scenarios where you can have multiple domain names pointing to the same site (www.foo.com, foo.com, rebrandedfoo.com), and you prefer users to use one of the domains over the other. There are also other parts of a website that usually need the hostname specified, e.g. generating a jwt for authentication.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andrew Williamson |
