具有2个以上参数的WCF自定义身份验证

时间:2014-01-05 19:03:04

标签: c# wcf

public class Authentication : UserNamePasswordValidator
{

   public override void Validate(string userName, string password, string companyID)
   { 

     //How can i pass a custom data like "companyID" to Validate method ?
   }

}

1 个答案:

答案 0 :(得分:0)

如果 companyID 是来自客户的标识符,则可能最简单的方法是将其作为userName的一部分传递:

//on client:
string username = companyID + ":" + realUsername;

并在验证器中拆分:

public override void Validate(string userName, string password) {
    string companyID, realUsername;
    string[] parts = userName.Split(':', 2);
    if (parts.Length == 2) {
        companyID = parts[0];
        realUsername = parts[1];
    }
}