目前我正在使用这样的登录方法登录,但我想将其嵌入到app.config文件中以便安全保存......
目前它看起来像这样。
WebClient c = new WebClient();
c.Credentials = new System.Net.NetworkCredential("UN", "PW", "server");
如何将其嵌入app.config文件???
答案 0 :(得分:5)
<appSettings>
<add key="NetworkCredentialUserName" value="UN" />
<add key="NetworkCredentialPassword" value="PW" />
</appSettings>
然后
var networkCredentialUserName = ConfigurationManager.AppSettings["NetworkCredentialUserName"];
var networkCredentialPassword = ConfigurationManager.AppSettings["NetworkCredentialPassword"];
c.Credentials = new System.Net.NetworkCredential(networkCredentialUserName, networkCredentialPassword , "server");
然而,这并不能确保它们安全。如果网络凭证用户名&amp;密码是敏感的,我会考虑使用像PKCS12ProtectedConfigurationProvider(一个nuget包)之类的东西来加密app.config appSettings部分。