0

扔在我的自定義成員船供應商我對的ValidateUser和事物提供的實現是迄今罰款,但現在突然了passwordFormat已經開始投擲NotImplementedException通過了passwordFormat在定義成員資格提供

NotImplementedException是由用戶代碼

未處理

我的web.config或自定義成員身份沒有變化。一些堆棧溢出問題的答案是在Web.config中的system.web下添加角色管理器,但它對我無效。另外,我嘗試了Josh here提出的答案,但仍然沒有區別。我正在使用十六進制編碼。其他除的ValidateUser的

沒有在我的自定義成員資格,這是因爲遵循

public override bool ValidateUser(string username, string password) 
    { 
     LoginModel model = new LoginModel 
     { 
      UserName = username, 
      Password = password, 
      ErrorMessage = "" 
     }; 

     User user = UserManager.AuthenticateUser(model); 

     if (user != null) 
     { 
      HttpContext.Current.Items.Add("User", user); 
      return true; 
     } 

     return false; 
    } 

回答

0

在這裏分享我的解決辦法的情況下,如果有人需要它來實現。

可以在web配置中定義PasswordFormat值,然後通過讀取其在MembershipPasswordFormat的PasswordFormat中的值來提供實現,如here中所述。

public override MembershipPasswordFormat PasswordFormat 
    { 
     string temp_format = config["passwordFormat"]; 
     if (temp_format == null) 
     { 
      temp_format = "Hashed"; 
     } 

     switch (temp_format) 
     { 
      case "Hashed": 
       passwordFormat = MembershipPasswordFormat.Hashed; 
       break; 
      case "Encrypted": 
       passwordFormat = MembershipPasswordFormat.Encrypted; 
       break; 
      case "Clear": 
       passwordFormat = MembershipPasswordFormat.Clear; 
       break; 
      default: 
       throw new ProviderException("Password format not supported."); 
     } 
    } 

如果有人不想設置web.config中的值,它也可以在會員密碼格式爲會員的東西很難在應用程序的生命週期的每個改變設置。

相關問題