2017-07-05 49 views
-1

我試圖通過執行UserNamePasswordValidator來提供用戶身份驗證。我添加了Microsoft.IdentityModelSystem.IdentityModel.Tokens.ValidatingIssuerNameRegistry nuget包。我正在使用.Net framework 4.5.2,但是我在執行UserNamePasswordValidator時遇到錯誤UserAuthentication「(缺少某些引用)」類型名稱或命名空間名稱選擇器不存在。我已經搜索了它,但無法找到解決方案,我錯過了什麼?下面是我的UserAuthentication找不到名稱空間System.IdentityModel.Services

public class UserAuthentication : System.IdentityModel.Selectors.UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 
     try 
     { 
      if (userName == "test" && password == "test123") 
      { 
       Console.WriteLine("Authentic User"); 
      } 
     } 
     catch (Exception ex) 
     { 
      throw new FaultException("Unknown Username or Incorrect Password"); 
     } 
    } 
} 

回答

4

添加NuGet包是不夠的(也是你的情況,不必要的),你需要引用的DLL在您的項目。在解決方案資源管理器中查找參考列表。

右鍵 - >添加引用 - >型System.IdentityModel在搜索框 - >選擇正確的DLL - >單擊確定 - >好走

+0

感謝您的幫助,它的工作。 – Leo

相關問題