模型视图控制器-在IIS下的ASP.net网站中使用c#从Windows通用凭据库检索凭据

本文关键字:检索 Windows 控制器 视图 IIS 下的 网站 net ASP 模型 | 更新日期: 2023-09-27 17:54:27

在IIS下的ASP.net网站中使用c#从Windows凭据存储中检索凭据我使用以下代码

本地机器和windows 10 IIS工作正常。但当我尝试在windows server 2012 R2不工作托管。我的代码:

    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);

以上代码运行在IIS下的windows server 2012 R。但以上代码无法检索用户名和密码。(cm总是null)我在控制台应用程序中使用了相同的代码,并且工作得很好。如有特殊要求,请告知。

模型视图控制器-在IIS下的ASP.net网站中使用c#从Windows通用凭据库检索凭据

您应该将IIS App Pool的"Load User Profile"参数设置为true。然后你的代码应该开始工作了。