我一直在为WCF服务创建自定义用户名/密码验证器,并在配置项customUserNamePasswordValidatorType上运行.我已经能够通过以下示例使我的代码工作,但我只是不明白发生了什么.不幸的是,MSDN文章没有提供太多细节.
这是Microsoft提供的示例:
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator, service" />
</serviceCredentials>
Run Code Online (Sandbox Code Playgroud)
我正在尝试了解customUserNamePasswordValidatorType的两个参数:"Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator"和"service".
有人可以帮我理解这些参数是什么意思吗?
谢谢!
Sco*_*ain 12
第一个参数是自定义验证函数的完全限定名称.第二个参数是包含函数的程序集的名称.
摘自一个更好的如何使用自定义验证器的示例(略微修改以适合您的示例)
namespace Microsoft.ServiceModel.Samples.CalculatorService
{
public class CustomUserNameValidator : UserNamePasswordValidator
{
// This method validates users. It allows in 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 FaultException("Unknown Username or Incorrect Password");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
以上内容将在一个名为的程序集中编译service.
| 归档时间: |
|
| 查看次数: |
10598 次 |
| 最近记录: |