How can we hide (invisible) some CodeBehind lines (for example a class) from other developers in a common project?

丶灬走出姿态 提交于 2019-12-12 04:58:12

问题


How can we hide (invisible) some CodeBehind lines (for example a class) from other developers in a common project?

I asked this question because today we were working on email codes and we wanted to send an email to all of programmers emails therewith sending an Email to our common web site email.

How can we hide our passwords from each other?

Is it possible to make 3 classess (for sending emails to 3 web developers) and hide or invisible those classes(class file or codebehind lines) and so each peogrammer can see only his class?

thanks in advance///

the email code is like :

protected void Button1_Click(object sender, EventArgs e)
{

    //create mail message
    MailMessage mail = new MailMessage();
    //set the address
    mail.From = new MailAddress("Kazemipour@gmail.com");
    mail.To.Add("aaak@yahoo.com");
    //set the content
    mail.Subject = "Project email";
    mail.Body = "Hello World!";

    //send the message
    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System‎‎.Net‎‎.NetworkCredential("aaa@gmail.com", "pass");
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;             
    smtp.EnableSsl = true;





    try
    {

        smtp.Send(mail);
        Button1.Text = "sent";
    }
    catch (System‎‎.Net.Mail.SmtpException exp)
    {
        Label1.Text = exp.ToString();
    }

}

回答1:


I would suggest creating and using a service account, not your personal account, for sending email from a web site. If possible, have your mail system admins exempt this service account from requiring a password to send email. In my experience, admins are usually pretty good about making exceptions for lower risk service accounts (because it isn't used by any human for normal internet activity).




回答2:


You should not be hard coding passwords into classes, you should put this kind of information in a config file. You can encrypt or hash the password for extra security. I am also not sure why you would need a password to send someone an email.

you could do something like:

string strEmail = System.Configuration.ConfigurationManager.AppSettings["Email"];
string strPassword = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
smtp.Credentials = new System‎‎.Net‎‎.NetworkCredential(strEmail,strPassword )

You could the store the email and password in the web/app.config file as below:

<appSettings>
  <add key="Email" value="arse@feck.com" />
  <add key="EmailPassword" value="ThePassword" />
</appSettings>

So long as each delevloper had their own config file they could keep their password secret but have generic code pull out the config file.



来源:https://stackoverflow.com/questions/3140338/how-can-we-hide-invisible-some-codebehind-lines-for-example-a-class-from-oth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!