我目前正在调试
#if Debug
new NetworkCredential("myUsername","myPassword", "myDomain");
#endif
一个好的解决方案是将密码存储在一个文件中,然后我读取该值(仅在调试时)。然后将该文件添加到 .gitignore?
生产环境永远不会读取此值,因为它是从已登录用户的 RestSharp 的 NtlmAuthenticator 获取的。
最佳答案
好的做法是将其保存在您添加到 .gitignore
您可以使用 appSettings
中的 file
属性来实现,例如:
<appSettings file="..\..\AppSettingsSecrets.config">
<!-- whatever keys that are kept on source control -->
</appSettings>
并在 AppSettingsSecrets.config
<appSettings>
<!-- SendGrid-->
<add key="mailAccount" value="My mail account." />
<add key="mailPassword" value="My mail password." />
<!-- Twilio-->
<add key="TwilioSid" value="My Twilio SID." />
<add key="TwilioToken" value="My Twilio Token." />
<add key="TwilioFromPhone" value="+12065551234" />
<add key="GoogClientID" value="1.apps.googleusercontent.com" />
<add key="GoogClientSecret" value="My Google client secret." />
</appSettings>
关于c# - 在源代码管理中存储您不想要的密码的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52151057/