title: Using a Web application method in a Console application
body: <p>I have been foloowing this guide <a href="http://www.aspsnippets.com/Articles/Send-user-Confirmation-email-after-Registration-with-Activation-Link-in-ASPNet.aspx" rel="nofollow noreferrer">http://www.aspsnippets.com/Articles/Send-user-Confirmation-email-after-Registration-with-Activation-Link-in-ASPNet.aspx</a> to create a system that send validation email on register and I seem to have stumbled into a small issue since the guide is suitable for Web Application and I need to modify it for Console Application,</p>
  
  <p>this piece of code is suitable for web application but i'm trying to change it to suit a console application.</p>
  
  <pre><code>body += "&lt;br /&gt;&lt;a href = '" +Request.Url.AbsoluteUri.Replace("CS.aspx", "CS_Activation.aspx?ActivationCode=" + activationCode) + "'&gt;Click here to activate your account.&lt;/a&gt;";
  </code></pre>
  
  <p>Tried reading about WebClient or the Uri options but I dont seem to figure out how to fetch the absolute Uri and add the required string to generate the activation link from a Console application.</p>
  
  <p>Will add more code if required.</p>
  
  <p>Tried following this SO <a href="https://stackoverflow.com/questions/20164298/how-to-build-a-url">How to build a Url?</a> but I cant seem to make it work properly.</p>
  
  <p>Activation Code Generation and saving it on DB.</p>
  
  <pre><code>private static void SendActivationEmail(string email, string userName, MySqlConnection mysqlCon)
      {
  
          string activationCode = Guid.NewGuid().ToString();
          using (mysqlCon)
          {
              using (MySqlCommand cmd = new MySqlCommand("UPDATE accounts SET ActivationCode=@ActivationCode " +
                                                         "WHERE Username=@Username;"))
              {
                  using (MySqlDataAdapter sda = new MySqlDataAdapter())
                  {
                      cmd.CommandType = CommandType.Text;
                      cmd.Parameters.AddWithValue("@Username", userName);
                      cmd.Parameters.AddWithValue("@ActivationCode", activationCode);
                      cmd.ExecuteNonQuery();
                      mysqlCon.Close();
                  }
              }
          }
  </code></pre>