连接上下文和UserNamePasswordValidator

时间:2012-06-20 12:43:17

标签: c# wcf security https wcf-security

我正在使用UserNamePasswordValidator进行WCF。我的代码很相似。我用数据库。 有没有人知道如何在此方法中获取有关当前连接上下文的信息。 我想记录不成功通话的IP地址

public class MyCustomUserNameValidator : UserNamePasswordValidator
{
    // This method validates users. It allows two users, test1 and test2 
    // with passwords 1tset and 2tset respectively.
    // This code is for illustration purposes only and 
    // MUST NOT be used in a production environment because it is NOT secure.   
    public override void Validate(string userName, string password)
    {
        if (null == userName || null == password)
        {
            throw new ArgumentNullException();
        }

        if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
        {
            throw new SecurityTokenException("Unknown Username or Password");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

检查

Getting the IP address of server in ASP.NET?

在您的例外情况下,您可以获得IP地址。