调试时我目前有
#if Debug
new NetworkCredential("myUsername","myPassword", "myDomain");
#endif
好的解决方案是将密码存储在文件中,然后读取值(仅在调试时).然后将该文件添加到.gitignore?
生产将永远不会读取此值,因为它是从登录用户的RestSharp的NtlmAuthenticator获取它的.
解决方法:
好的做法是将其保存在添加到.gitignore中的秘密配置文件中
您可以使用appSettings中的文件属性来完成此操作,例如:
<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>