Search code examples
c#model-view-controllercredential-manager

Retrieve Credentials from Windows generic Credentials Store using C# in ASP.net website under IIS


Retrieve Credentials from Windows Credentials Store problem using C# in ASP.net website under IIS I am using following code

Local machine and windows 10 IIS its working fine. but when i try to hosting in windows server 2012 R2 not working. My code:

    var cm = new Credential();
cm.Target = "targetname";
cm.Type = CredentialType.Generic;
if (!cm.Exists())
{
    Console.WriteLine("cm is null");
}
cm.Load();
Console.WriteLine(cm.Password);
Console.WriteLine(cm.Username);

Above code running on windows server 2012 R under IIS. But above code is not able to retrieve username and password.(cm is null always) I used same code in my console application and works fine. Please let me know any special instruction need to follow.


Solution

  • You should switch "Load User Profile" parameter of IIS App Pool to true. Then your code should start working.