修改.config文件中的configProtectedData部分

本文关键字:configProtectedData 部分 config 文件 修改 | 更新日期: 2023-09-27 18:18:18

对于以下内容:

<configProtectedData >
<providers>
  <clear />
  <add CertSubjectDistinguishedName="localhost" name="X509ProtectedConfigProvider" type="X509ProtectedConfig.X509ProtectedConfigProvider, X509ProtectedConfigProvider" />
</providers>
</configProtectedData>

如何修改:

CertSubjectDistinguishedName="localhost"

并将"localhost"替换为其他内容?

我不知道如何在"configProtectedData"部分阅读和修改它。由于

修改.config文件中的configProtectedData部分

我使用XMLDocument:

解决了这个问题。
    string path = Path.Combine(targetDirectory, applicationExecutableName);
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(path);
    XmlNode node = xmlDoc.SelectSingleNode("configuration/configProtectedData/providers");
    node.InnerXml = string.Format("<add CertSubjectDistinguishedName='"{0}'" CertStoreName='"{1}'" name='"X509ProtectedConfigProvider'" type='"ProtectedConfigProvider.X509ProtectedConfigProvider, X509ProtectedConfigProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=098027505e2ed139'" />", certSubject, certStoreName);
    xmlDoc.Save(path);

如果有人知道一个更好的方法,请张贴一个样本。由于

相关文章:
  • 没有找到相关文章