我正在尝试在 ASP.Net 4.0 Web 应用程序中更新 LinqKit,该应用程序使用加密的配置部分来混淆连接字符串部分。我们还使用配置转换。
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configProtectedData>
<providers>
<add keyContainerName="FooBarKeys" useMachineContainer="true" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" name="FooBarProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</configProtectedData>
<connectionStrings configProtectionProvider="FooBarProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
...
对于面向 .Net 4.0 的项目,LinqKit 1.1.7+ 依赖于 Microsoft.Bcl.Async,并且在任何引用使用 Microsoft.Bcl.Async 的类库的项目中都需要 Microsoft.Bcl.Build。
当我构建时,我得到这个错误:
The "EnsureBindingRedirects" task failed unexpectedly.
System.Xml.XmlException: App.config must have root configuration element. Line 2, position 2.
at Roxel.BuildTasks.EnsureBindingRedirects.ThrowXmlException(String message, Exception inner, IXmlLineInfo info)
at Roxel.BuildTasks.EnsureBindingRedirects.LoadAppConfig(String appConfigPath)
at Roxel.BuildTasks.EnsureBindingRedirects.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
File: packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets line 97
如果我更改<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
为<configuration>
,我会收到 web.config 的 XML 验证警告:
The 'keyContainerName' attribute is not allowed.
The 'useMachineContainer' attribute is not allowed.
The 'description' attribute is not allowed.
The 'configProtectionProvider' attribute is not allowed.
The element 'connectionStrings' has invalid child element 'EncryptedData' in namespace 'http://www.w3.org/2001/04/xmlenc#'. List of possible elements expected: 'add, remove, clear'.
我尝试使用<configuration xmlns:c="http://schemas.microsoft.com/.NetConfiguration/v2.0">
,<c:configProtectedData>
和<c:connectionStrings>
。这验证,但在运行时失败:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Code 0x80070032
Config Error The configuration section 'c:configProtectedData' cannot be read because it is missing a section declaration
Config Source:
5: </configSections>
**6: <c:configProtectedData>**
7: <providers>
如何在 .Net 4.0 Web 应用程序中使用这些库,使其构建、具有有效的 web.config 并运行?