Configuring the Web.Config file

0

I wonder if I can leave the recipient's email in web.config, if so, how do I deploy it. I created a variable and gave the value of the email, however if I need to change I will have to compile dnv, if I can put the recipient in web.config and only get the value from there it will not have to compile every time the the email is changed. Thanks

public void montarEmail(string nome, string email, string celular, string telefone, string assunto, string mensagem)
        {
            var servicoDeEmail = new ServicoDeEmail();

            var destinatario = "[email protected]";



            string corpoDoEmail = "Dados do contato: <br />" +
                                   "<br />" +
                                   "<b>Nome: </b>" + nome + "<br />" +
                                   "<b>Email: </b>" + email + "<br />" +
                                   "<b>Telefone: </b>" + telefone + "<br />" +
                                   "<b>Celular: </b>" + celular + "<br />" +
                                   "<br />" +
                                   "<b>Mensagem: </b>" + mensagem;

            servicoDeEmail.EnviarEmail(destinatario, assunto, corpoDoEmail);

        }
    
asked by anonymous 02.03.2018 / 14:23

1 answer

3

What you can do is to use the ConfigurationManager class by adding the recipient in Web.Config as follows:

<configuration>
   ....
   <appSettings>
      <add key="myKey" value="myValue"/>
   </appSettings>
   ....
</configuration>

And access the value as follows:

string userName = WebConfigurationManager.AppSettings["myKey"]

As the following link shows: link

    
02.03.2018 / 14:29