在源代码管理中存储您不想要的密码的位置

Where to store a password that you don't want in source control

在调试时我目前有

#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>