.NET Core 2.2 > 不支持始终加密

Posted

技术标签:

【中文标题】.NET Core 2.2 > 不支持始终加密【英文标题】:.NET Core 2.2 > Always Encrypted Not Supported 【发布时间】:2021-08-21 11:25:02 【问题描述】:

使用 .NET Core 2.2 和 SQL Always Encrypted 时出现以下错误。 2.2 支持吗?

不支持关键字:“列加密设置”。

实际上,如您所见,我在 AppContext 构造函数中运行 DB 迁移。

public SenSightsContext(DbContextOptions<SenSightsContext> options)
        : base(options)
    
        Database.Migrate();
    

它以前不工作,它给了我一个异常,我通过安装 Microsoft.Data.SqlClient 修复了它。 现在它给了我关于 SeedData 方法的错误,如下所示。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, RoleManager<ApplicationRole> roleManager, AppUserManager userManager, ILoggerManager loggerManager)
    

        if (env.IsDevelopment())
        
            app.UseDeveloperExceptionPage();
        
        else
        
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        
        //custom exception middleware.
        app.ConfigureExceptionHandler(loggerManager);

        //Seed Data
        SeedData(roleManager, userManager).Wait();

        // global cors policy
        app.UseCors(x => x
            .AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader());

        app.UseAuthentication();
        app.UseHttpsRedirection();

        // Enable middleware to serve generated Swagger as a JSON endpoint.
        app.UseSwagger();

        // Enable middleware to serve swagger-ui (html, JS, CSS, etc.),
        // specifying the Swagger JSON endpoint.
        app.UseSwaggerUI(c =>
        
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "SenSights API V1");
            //c.RoutePrefix = string.Empty;  // Set Swagger UI at apps root
        );
        var path = Path.Combine(env.ContentRootPath, "Uploads", "ProfileImages");

        if (!Directory.Exists(path))
        
            Directory.CreateDirectory(path);
        

        app.UseStaticFiles(new StaticFileOptions
        
            FileProvider = new PhysicalFileProvider(path),
            RequestPath = "/ProfileImages"
        );
        app.UseMvc();
    

下面是栈

在 System.Data.SqlClient.SqlConnectionStringBuilder.GetIndex(String 关键字) 在 System.Data.SqlClient.SqlConnectionStringBuilder.set_Item(字符串关键字,对象值) 在 System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(字符串值) 在 System.Data.SqlClient.SqlConnectionStringBuilder..ctor(字符串连接字符串) 在 Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.get_IsMultipleActiveResultSetsEnabled() 在 Microsoft.EntityFrameworkCore.Storage.RelationalConnection.d__61.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.&lt;BufferlessMoveNext&gt;d__12.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.&lt;ExecuteAsync&gt;d__72.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.d__11.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 D:\a\1\s\Ix.NET\Source\System.Interactive.Async\First.cs:line 151 中的 System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at System.Linq.AsyncEnumerable.&lt;FirstOrDefault_&gt;d__1651.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.TaskResultAsyncEnumerable1.Enumerator.d__3.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Select.cs:line 118 中的 System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator2.d__7.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 112 中的 System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at System.Linq.AsyncEnumerable.AsyncIterator1.d__10.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.d__5.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.&lt;ExecuteSingletonAsyncQuery&gt;d__211.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNetCore.Identity.RoleManager1.d__33.MoveNext() 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在 C:\WorkSpaces\Markitech\Sensight\sensights_backend\SensSights-API\Startup.cs: 256 行中的 CMAD_API.Startup.d__6.MoveNext() 处

任何帮助将不胜感激 谢谢

【问题讨论】:

.NET Core 3.0 + 现在支持始终加密 这能回答你的问题吗? .NET Core 3.1 Always Encrypted @Charlieface 不,我的 .NET Core 版本不是 3.1,而是 2.2,我已经看过这个链接,我知道 3.0+ 版本支持始终加密,其实我不想要更新我的 .NET Core 版本 【参考方案1】:

需要添加以下包引用Microsoft.Data.SqlClient(见nuget)并使用这个Microsoft.Data.SqlClient而不是System.Data.SqlClient。

.NET Core 3.0+ 版本支持

【讨论】:

以上是关于.NET Core 2.2 > 不支持始终加密的主要内容,如果未能解决你的问题,请参考以下文章

如何解决“当前 .NET SDK 不支持面向 .NET Core 2.2”

当前的 .Net SDK 不支持针对 .Net Core 2.2 目标 .Net Core 2.1 或更低版本 [重复]

IsAuthenticated 在自定义授权属性(.NET Core 2.2 和 JSON Web 令牌)中始终为 false

asp.net core 2.2 发布文件导致 http/415 不支持的媒体类型

.net core 2.2 和广泛开放的 CORS

Asp .Net Core 2.2 Razor Pages Ajax Call Post 不工作