我试图在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 App中使用这些库,使其构建,具有有效的web.config并运行?