I'm attempting to use the following code from 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;
}
I am attempting to add the code above to a class in ac# class library, and to fix the error, I have tried the answer in the following thread: https://forums.asp.net/t/1205345.aspx?The+type+or+namespace+name+Configuration+does+not+exist+in+the+namespace+System+Web+ . The suggested answer was: You need to add System.Configuration DLL via "Add Reference" dialog box. Right click References and select Add Reference, then select System.Configuration under the .NET tab.
However, when I try to add the System.Configuration DLL as a reference, I don't see it in the list.
Where can I find this System.Configuration DLL please?
================== UPDATE ======================
Adding Assemblies-related screenshots. There are no options to add System.Configuration assemblies:
Both commenters of the original post were correct. I'm just going to sum up the answer here:
I needed to create a .NET Framework class library, not a .NET Standard class library because WebConfigurationManager
is only available for .NET Framework.
Right click on the class library's References -> Add Reference -> Assemblies -> Find both System.Web.dll
and System.Configuration.dll
-> OK.
No more error!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.