I’m trying to figure out how to write a dynamic URL (a.k.a. activationlink) in a repository class.
Here’s what was working with but I’m not sure how to do the “http://mysite.com” dynamically:
private static void SendActivationEmail(User user)
{
string ActivationLink = "http://mysite.com" +
user.Username + "/" + user.NewEmailKey;
var message = new MailMessage("email@email.com", user.Email)
{
Subject = "Activate your account",
Body = ActivationLink
};
var client = new SmtpClient("smtp.email.com");
client.Send(message);
}
for your case you could do something like this
if you know want the user to be redirected to a Activate web page via a url. then you would want to format the link via a query string
this is an example use it how you need to to fit your UseCase
HttpContext.Current.Request.Url.Hostinstead of
HttpContext.Current.Request.UrlFor your local dev environment you will be getting
localhost, but when you deploy this to some web server, this would correctly update itself to the hosted web server url.Ideally, you would have some path that would contain the querystring and then corresponding code in page load to validate and use the querystring.
Example:
Note: You could use the HttpContext.Current.Request.Url also and that would redirect you to the current page with querystring:
And then in page load of AccountValidate.aspx or current page: