【问题标题】:Modify configProtectedData section in .config file修改 .config 文件中的 configProtectedData 部分
【发布时间】:2013-06-09 20:46:05
【问题描述】:

以下:

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

如何修改:

CertSubjectDistinguishedName="localhost"

并用不同的东西替换“localhost”?

我不知道如何阅读“configProtectedData”部分并对其进行修改。 谢谢

【问题讨论】:

    标签: c# asp.net c#-4.0 app-config


    【解决方案1】:

    我使用 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);
    

    如果有人知道更好的方法,请发布示例。谢谢

    【讨论】:

    • 如何在Web.config中为configProtectedData生成PublicKeyToken?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    相关资源
    最近更新 更多