簡體   English   中英

在IIS下的ASP.net網站中使用C#從Windows通用憑據存儲中檢索憑據

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

從Windows Credentials中檢索憑據在IIS下的ASP.net網站中使用C#存儲問題我正在使用以下代碼

本地機器和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 App Pool的“加載用戶配置文件”參數切換為true。 那么你的代碼應該開始工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM