博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to: Use a Custom User Name and Password Validator(WCF)
阅读量:4924 次
发布时间:2019-06-11

本文共 3390 字,大约阅读时间需要 11 分钟。

在wcf中使用自定义的用户名和密码验证方式

https://msdn.microsoft.com/en-us/library/aa702565.aspx

http://www.codeproject.com/Articles/96028/WCF-Service-with-custom-username-password-authenti

 

To configure a service to use a custom user name and password validator

  1. Configure a binding that uses message security over any transport or transport-level security over HTTP(S).

    When using message security, add one of the system-provided bindings, such as a , or a  that supports message security and the UserName credential type.

    When using transport-level security over HTTP(S), add either the  or , a  or a  that uses HTTP(S) and the Basic authentication scheme.

    NoteNote

    When .NET Framework version 3.5 or later is used, you can use a custom username and password validator with message and transport security. With WinFX, a custom username and password validator can only be used with message security.

    TipTip

    For more information on using <netTcpBinding> in this context, see 

    1. In the configuration file, under the  element, add a  element.

    2. Add a  or  element to the bindings section. For more information about creating an WCF binding element, see .

    3. Set the mode attribute of the  or  to Message, Transport, or TransportWithMessageCredential.

    4. Set the clientCredentialType attribute of the  or .

 

如果第3步使用的是Security是Message,那么就设置MessageSecurity的MessageClientCredentialType为UserName

When using message security, set the clientCredentialType attribute of the  to UserName.

When using transport-level security over HTTP(S), set the clientCredentialType attribute of the  or  to Basic.

NoteNote

When a WCF service is hosted in Internet Information Services (IIS) using transport-level security and the  property is set to , the custom authentication scheme uses a subset of Windows authentication. That is because in this scenario, IIS performs Windows authentication prior to WCF invoking the custom authenticator.

 

For more information about creating an WCF binding element, see .

The following example shows the configuration code for the binding.

 

netTcpBinding的security的Mode属性,可以设置为4种类型,选择Message

 
如果Mode设置为Message的话,那么就需要设置MessageSecurity的MessageClientCredentialType为UserName
如果Mode设置为Transport的话,那么就需要设置TransportSecurity的TransportClientCredentialType

 

 

 

2.Configure a behavior that specifies that a custom user name and password validator is used to validate user name and password pairs for incoming  security tokens.

  1. As a child to the  element, add a  element.

  2. Add a  to the  element.

  3. Add a  element and set the name attribute to an appropriate value.

  4. Add a  to the  element.

  5. Add a  to the .

  6. Set the userNamePasswordValidationMode to Custom.

    Important noteImportant

    If the userNamePasswordValidationMode value is not set, WCF uses Windows authentication instead of the custom user name and password validator.

  7. Set the customUserNamePasswordValidatorType to the type that represents your custom user name and password validator.

The following example shows the <serviceCredentials> fragment to this point.

<serviceCredentials>

<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator, service" />

</serviceCredentials>

 

 

转载于:https://www.cnblogs.com/chucklu/p/4682539.html

你可能感兴趣的文章
Codeforces Round #403(div 2)
查看>>
大型网站处理高并发要点技术
查看>>
Codeforces-1059D:Nature Reserve问最大的圆包含全部点
查看>>
牛客练习赛24
查看>>
转发推荐系统文章
查看>>
并排,快排和冒泡排序
查看>>
BZOJ 1073: [SCOI2007]kshort
查看>>
在centos上安装tomcat
查看>>
第十四章 异常处理
查看>>
超链接-a标签
查看>>
转载ASP.NET MVC中Session的处理机制
查看>>
Makefile 語法簡介
查看>>
sql面试题(学生表_课程表_成绩表_教师表)
查看>>
Sublime 保存时自动转换tab成空格
查看>>
atom 插件 python语法验证linter-flake8-------填坑
查看>>
cuda中当元素个数超过线程个数时的处理案例
查看>>
转:PCL+VS2010环境配置
查看>>
volatile
查看>>
uploadify3.2.1加载时,报NetworkError 404 Not Found或NetworkError forbidden错误
查看>>
Vim 常用命令总结
查看>>