aKz*_*enT 5 c# authentication silverlight wcf web-services
我有一个具有不同方法的 UserAccountService,其中一些需要对用户进行身份验证(例如 ChangePassword、ChangeUserData),而另一些则不需要(RegisterUser)。
但是,我似乎无法使其正常工作,因此只有某些方法需要身份验证。
需要身份验证的方法装饰有
[PrincipalPermission(SecurityAction.Demand, Authenticated = true)]
Run Code Online (Sandbox Code Playgroud)
在我的 app.config 中,我指定了一个绑定,它使用加密并请求用户名凭据:
<binding name="authenticatedBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
Run Code Online (Sandbox Code Playgroud)
(我使用的是 basicHttpBinding)
我还配置了一个自定义身份验证提供程序:
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="..." />
</serviceCredentials>
Run Code Online (Sandbox Code Playgroud)
使用此配置,我似乎无法在未经身份验证的情况下调用服务上的任何方法。
如果我省略了安全配置,那么我可以调用不需要身份验证的方法,但不再传输消息凭据。
我如何配置我的服务,以便它允许调用所有方法,并且只需要在 PrincipalPermission 要求时设置用户名/密码?
我使用 Silverlight 作为我的客户,如果这很重要的话......
谢谢!
安全设置可以在端点级别进行细粒度设置,但不能在合同内进行细粒度设置 - 因此您无法以您想要的方式组合安全和不安全的方法。我会建议