Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net <;连接字符串>;未在app.config中加密节_.net_Vb.net_Encryption - Fatal编程技术网

.net <;连接字符串>;未在app.config中加密节

.net <;连接字符串>;未在app.config中加密节,.net,vb.net,encryption,.net,Vb.net,Encryption,接下来,我将尝试加密app.config文件中的整个部分。程序运行时,我可以打开bin/Debug/MyApp.vshost.exe.config,查看是否加密。但是,如果我让程序正常运行、完成并退出,则不会在文件中保存任何内容,就像它刷新所有设置一样 Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) Dim sectio

接下来,我将尝试加密app.config文件中的整个
部分。程序运行时,我可以打开
bin/Debug/MyApp.vshost.exe.config
,查看
是否加密。但是,如果我让程序正常运行、完成并退出,则不会在文件中保存任何内容,就像它刷新所有设置一样

  Dim config As Configuration =  
    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    Dim section As ConnectionStringsSection =  
    DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
    If section.SectionInformation.IsProtected Then
        'Remove encryption 
        section.SectionInformation.UnprotectSection()
    Else
        'Encrypt  
         section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
    End If
        section.SectionInformation.ForceSave = True
        config.Save(ConfigurationSaveMode.Full)
    Dim sectionXmlas As String = 'result of encryption 
                    section.SectionInformation.GetRawXml()

要以编程方式实现此功能,您必须调用

config.refreshsection

调用Save将调整物理文件,但在进行上述调用之前,它将缓存在内存中。

您必须调用config.refreshsection才能使此工作正常,
配置
类中没有
刷新节
命令/函数
刷新节
配置管理器
类中的共享函数。使用要刷新的节名调用
ConfigurationManager.RefreshSection(sectionName)
。@duck
ConfigurationManager.RefreshSection(“连接字符串”)
也没有做任何事情,我想
GetRawXML()
在返回数据之前对受保护的部分进行解密-因此您将始终从调用中获取未加密的数据。您能看到基础文件中所做的更改吗<调用
ProtectSection()
后,code>section.SectionInformation.IsProtected应返回true。您可能会在该文件的vshost版本中看到一些奇怪的行为。如果直接而不是通过VisualStudio运行程序,会发生什么?你应该看到加密卡在周围。