jignesh
jignesh

Reputation: 1669

WCF Custom Authentication using UserNamePasswordValidator

I have used UserNamePasswordValidator for Custom Authentication in WCF service.I am using static variable and set the value of UserId variable as below.As I am using static variable it will overwrite UserId value between two requests.How can I get UserId in service method?

public class CustomUserNameValidator : UserNamePasswordValidator
{
   public static int IsSuccess = 0;
   public static int UserId=0;
   public override void Validate(string userName, string password)
   {

        this.IsValidate(username,password);
   }

  private int isValidate(string stUserName, string password)
  {
     try
     {
       LoginUser objUser=DBContext.ValidateUser(stUserName,password);
       if(objUser!=null)
        {
            UserId=objUser.UserId;
            IsSuccess=1;
        }
     }
     Catch(Exception ex)
     {
       Logger.Log(ex);
     }

  }
}

Upvotes: 2

Views: 3298

Answers (1)

jignesh
jignesh

Reputation: 1669

I got the solution that How to get Username and Password in WCF service method while using UsernamePasswordValidator with wshttpbinding in WCF.

Really nice post http://www.neovolve.com/2008/04/07/wcf-security-getting-the-password-of-the-user/

Upvotes: 1

Related Questions