我正在尝试使用来自 https://learn.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application 的以下代码。
我试图将上述代码添加到C#类库中的一个类中,为了解决错误,我尝试了以下线程中的答案:https://forums.asp.net/t/1205345.aspx?The+type+or+namespace+name+Configuration+does+not+exist+in+the+namespace+System+Web+。建议的答案是:您需要通过“添加引用”对话框添加System.Configuration DLL。右键单击“引用”,选择“添加引用”,然后在.NET选项卡下选择System.Configuration。
但是,当我试图添加System.Configuration DLL作为引用时,我在列表中看不到它。
请问我在哪里可以找到这个System.Configuration DLL呢?
================== 更新 ======================
添加程序集相关截图。没有添加System.Configuration程序集的选项:
//add these using statements
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Threading.Tasks;
using System.Web.Configuration;
//this is an optional property to hold the secret after it is retrieved
public static string EncryptSecret { get; set; }
//the method that will be provided to the KeyVaultClient
public static async Task<string> GetToken(string authority, string resource, string scope)
{
var authContext = new AuthenticationContext(authority);
ClientCredential clientCred = new ClientCredential(WebConfigurationManager.AppSettings["ClientId"],
WebConfigurationManager.AppSettings["ClientSecret"]);
AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);
if (result == null)
throw new InvalidOperationException("Failed to obtain the JWT token");
return result.AccessToken;
}
我试图将上述代码添加到C#类库中的一个类中,为了解决错误,我尝试了以下线程中的答案:https://forums.asp.net/t/1205345.aspx?The+type+or+namespace+name+Configuration+does+not+exist+in+the+namespace+System+Web+。建议的答案是:您需要通过“添加引用”对话框添加System.Configuration DLL。右键单击“引用”,选择“添加引用”,然后在.NET选项卡下选择System.Configuration。
但是,当我试图添加System.Configuration DLL作为引用时,我在列表中看不到它。
![](https://istack.dev59.com/cjzjX.webp)
================== 更新 ======================
添加程序集相关截图。没有添加System.Configuration程序集的选项:
![enter image description here](https://istack.dev59.com/Qc1Pn.webp)
![enter image description here](https://istack.dev59.com/r9Ch0.webp)
System.Web.Configuration
导入项目的位置。 - aBlazeWebConfigurationManager
是为ASP.NET项目设计的,而你的项目不是。 - Camilo Terevinto