加密的配置文件不适用于Windows服务

时间:2016-09-05 23:36:30

标签: .net app-config

我正在通过" aspnet_regiis -pef"加密我的app.config。方法

加密和解密工作正常。如果我解密配置文件,该服务运行正常。当我加密配置的两个部分(通过上面的方法)时,服务拒绝启动,w错误如下。

但是在运行时,框架会在阅读配置时抛出大量的异常..."错误(下面)。

我认为.config加密对.NET应用程序通常是透明的吗? (在IIS,cmd行等下)

我可以通过解密来解决错误:" aspnet_regiis -pdf"然后通过" aspnet_regiis -pef"

返回

该服务是.NET 4.6,VS 2015,log4net和nhibernate。

要清楚,.config是有效的。以下是步骤:

1)清除,干净,未加密的app.config:控制台应用程序正常运行

2)粘贴在< configProtectedData>部分(加密所需),然后使用" aspnet_regiis -pef" (重写配置,如果我用上面的粘贴损坏它,aspnet_regiis chokes - 如果它工作,config是有效的)

3)现在应用程序不会运行,错误如下。

4)好的,所以我通过" aspnet_regiis -pdf"解密,重新添加< configSections>现在应用程序正常。 (同样,如果xml被破坏了,#34; aspnet_regiis -pdf"会爆炸,但它没有,它可以正常工作。)

我可以整天重复上述内容。

有一件事让我头疼:

使用" aspnet_regiis -pef"加密时< configSections>迷路了。 aspnet_regiis.exe没有写出来。如果在加密后手动将其放入,System.Configuration模块会抱怨只能有一个以保留的" config"开头的部分。关键字。

我不确定那是什么意思。

我应该去哪个方向?

log4net:ERROR DefaultRepositorySelector: Exception while reading ConfigurationSe
ttings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed t
o initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognize
d configuration section hibernate-configuration. (C:\Inetpub\ProofConcept.Service.Se
rver\bin\Release\ProofConcept.Service.Server.exe.Config line 33)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor
eLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(Configurat
ionSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.PrivilegedConfigurationManager.GetSection(String sect
ionName)
   at System.Diagnostics.DiagnosticsConfiguration.Initialize()
   at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
   at System.Diagnostics.TraceInternal.InitializeSettings()
   at System.Diagnostics.TraceInternal.WriteLine(String message)
   at log4net.Util.LogLog.EmitErrorLine(String message)
log4net:ERROR DefaultRepositorySelector: Exception while reading ConfigurationSe
ttings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed t
o initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognize
d configuration section hibernate-configuration. (C:\Inetpub\ProofConcept.Service.Se
rver\bin\Release\ProofConcept.Service.Server.exe.Config line 33)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor
eLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(Configurat
ionSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at log4net.Util.SystemInfo.GetAppSetting(String key)
log4net:ERROR DefaultRepositorySelector: Exception while reading ConfigurationSe
ttings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed t
o initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognize
d configuration section hibernate-configuration. (C:\Inetpub\ProofConcept.Service.Se
rver\bin\Release\ProofConcept.Service.Server.exe.Config line 33)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor
eLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(Configurat
ionSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at log4net.Util.SystemInfo.GetAppSetting(String key)
log4net:ERROR DefaultRepositorySelector: Exception while reading ConfigurationSe
ttings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed t
o initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognize
d configuration section hibernate-configuration. (C:\Inetpub\ProofConcept.Service.Se
rver\bin\Release\ProofConcept.Service.Server.exe.Config line 33)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor

0 个答案:

没有答案