gpt4 book ai didi

c# - “IDataProtectionBuilder”不包含 'ProtectKeysWithAzureKeyVault' MVC dotnet core 3.1 的定义

转载 作者:行者123 更新时间:2023-12-02 23:13:57 24 4
gpt4 key购买 nike

我收到一条错误,无法将 ProtectKeysWithAzureKeyVault 添加到 MVC Startup.cs dotnet 3.1 类中的 IDataProtectionBuilder

引用了 Microsoft.Extensions.Configuration.AzureKeyVault,并且 PersistKeysToAzureBlobStorage 工作正常,但我想使用 Azure Key Vault 来加密静态 key 。

根据Microsoft documents这段代码应该可以工作

public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.PersistKeysToAzureBlobStorage(new Uri("<blobUriWithSasToken>"))
.ProtectKeysWithAzureKeyVault("<keyIdentifier>", "<clientId>", "<clientSecret>");
}

这是我的代码

using Microsoft.AspNetCore.DataProtection;
using Microsoft.Azure.Storage.Blob;
using Microsoft.Azure.Storage;

public void ConfigureServices(IServiceCollection services)
{
if (CloudStorageAccount.TryParse(Configuration["AzureDataProtection:StorageConnectionString"], out CloudStorageAccount storageAccount))
{
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference(Configuration["AzureDataProtection:ContainerName"]);
container.CreateIfNotExistsAsync();
services.AddDataProtection()
.PersistKeysToAzureBlobStorage(container, $"{Configuration["AzureDataProtection:ApplicationName"]}{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}keys.xml")
.ProtectKeysWithAzureKeyVault(Configuration["AzureDataProtection:DataProtectionKey"], Environment.GetEnvironmentVariable("AZURE_CLIENT_ID"), Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET"));
.SetApplicationName(Configuration["AzureDataProtection:ApplicationName"]);
}
}

我一直在假设我错过了一个包,但无法弄清楚是什么 - 这是整个项目文件。

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<UserSecretsId>ed790662-005d-4160-802c-4900c2d6daf0</UserSecretsId>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
<Content Include="Styles\ovbootstrap.css" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Apis.Auth" Version="1.43.0" />
<PackageReference Include="Google.Apis.Drive.v3" Version="1.43.0.1835" />
<PackageReference Include="Google.Apis.Sheets.v4" Version="1.43.0.1848" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.AzureStorage" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestSharp" Version="106.10.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Temp\" />
<Folder Include="Views\Shared\Components\MeasurerSurveyorFitterFilterMenu\" />
<Folder Include="Views\Shared\Components\ExportHeaderSummary\" />
<Folder Include="wwwroot\css\" />
<Folder Include="wwwroot\js\" />
<Folder Include="wwwroot\lib\" />
<Folder Include="wwwroot\images\" />
</ItemGroup>
</Project>

但我收到此错误:CS1061“IDataProtectionBuilder”不包含“ProtectKeysWithAzureKeyVault”的定义,并且找不到接受“IDataProtectionBuilder”类型的第一个参数的可访问扩展方法“ProtectKeysWithAzureKeyVault”(您是否缺少 using 指令或程序集引用?)

我尝试引用 Microsoft.AspNetCore.DataProtection.AzureStorage 以及通过清理/重建。

非常感谢任何建议!

最佳答案

您似乎缺少 Key Vault 软件包 https://www.nuget.org/packages/Microsoft.AspNetCore.DataProtection.AzureKeyVault/ .

我通过谷歌搜索名称发现了这一点,这使我找到了定义该函数的程序集名称。

关于c# - “IDataProtectionBuilder”不包含 'ProtectKeysWithAzureKeyVault' MVC dotnet core 3.1 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60021365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com