gpt4 book ai didi

c# - 连接上下文和 UserNamePasswordValidator

转载 作者:行者123 更新时间:2023-11-30 18:38:32 27 4
gpt4 key购买 nike

我正在为 WCF 使用 UserNamePasswordValidator。我的代码是相似的。我用数据库。有谁知道如何在此方法中获取有关当前连接上下文的信息。我想记录不成功调用的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");
}
}
}

最佳答案

检查这个

Getting the IP address of server in ASP.NET?

在您的异常(exception)情况下,您可以获得 ip 地址。

关于c# - 连接上下文和 UserNamePasswordValidator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11119825/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com