错误:名称空间“System.Web”中不存在类型或命名空间名称“Configuration”

问题描述 投票:1回答:1

我正在尝试使用https://docs.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application中的以下代码

//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。右键单击References并选择Add Reference,然后在.NET选项卡下选择System.Configuration。

但是,当我尝试添加System.Configuration DLL作为参考时,我没有在列表中看到它。

我在哪里可以找到这个System.Configuration DLL?

==================更新======================

添加与Assemblies相关的屏幕截图。没有选项可以添加System.Configuration程序集:enter image description here

enter image description here

c# asp.net-mvc azure-active-directory azure-keyvault
1个回答
1
投票

原帖的两位评论者都是正确的。我在这里总结一下答案:

  1. 我需要创建一个.NET Framework类库,而不是.NET Standard类库,因为WebConfigurationManager仅适用于.NET Framework。 enter image description here
  2. 右键单击类库的引用 - >添加引用 - >程序集 - >查找System.Web.dllSystem.Configuration.dll - >确定。

没有更多错误!

© www.soinside.com 2019 - 2024. All rights reserved.