我的 web.config 中有一个自定义部分需要加密。此自定义配置部分使用 configSource 属性指向单独的配置文件(因为该文件不受源代码控制),我希望对这个单独的配置文件进行加密。我没有运气使用 aspnet_regiis.exe
来加密此部分。
我想要实现的目标可能吗?
我的 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="protectedAppSettings" type="System.Configuration.NameValueSectionHandler, System,Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<protectedAppSettings configSource="config\EnvironmentConfigurations\ProtectedAppSettings.config" />
</configuration>
我的自定义配置文件:
<?xml version="1.0" encoding="utf-8"?>
<protectedAppSettings>
<add key="XXX" value="xxx"/>
</protectedAppSettings>
我已将 aspnet_regiis 添加到我的路径中,以便我可以从站点的根目录调用它。这是我正在执行的命令:
aspnet_regiis -pef protectedAppSettings ""
从该命令获得的输出告诉我加密已成功
我找到了this link这表明它应该正常工作,但它不适合我..
最佳答案
这是因为我用来定义配置部分的类型。尽管没有文档证明这一点,但 NameValueSectionHandler
类型在用于配置源时似乎不会加密。解决方案是将类型更改为 System.Configuration.AppSettingsSection 并且加密工作正常
关于asp.net - 是否可以加密从 web.config 指定为 configSource 的配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40650793/