是否可以在自托管 WCF 服务中使用 ASP.NET MembershipProvider/RoleProvider?
我正在尝试使用自定义 ASP.NET MembershipProvider 和 RoleProvider 来处理我的服务的安全性。该服务在控制台应用程序中自托管,而不是在 IIS 中。 我使用带有基本身份验证的 webHttpBinding。我将 serviceCredentials 和 serviceAuthorization 配置为使用提供程序。提供者真正被初始化。但 WCF 似乎忽略了我的设置并尝试将用户登录到 Windows。我从事件日志中发现了这一点,并通过将我的 Windows 凭据发送到服务来证明。下面你可以看到我的配置和调试截图。为什么使用 windows 进行身份验证?也许没有 IIS 就无法使用 ASP.NET 身份验证提供程序?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<roleManager
enabled="true"
defaultProvider="CustomRoleProvider">
<providers>
<clear/>
<add
name="CustomRoleProvider"
type="CustomRoles.CustomRoleProvider, CustomRoles"/>
</providers>
</roleManager>
<membership defaultProvider="CustomMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="CustomMembershipProvider"
type="CustomRoles.CustomMembershipProvider, CustomRoles"/>
</providers>
</membership>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttp">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Service">
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="CustomRoleProvider" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="CustomMembershipProvider" />
</serviceCredentials>
<serviceSecurityAudit auditLogLocation="Application" serviceAuthorizationAuditLevel="SuccessOrFailure"
messageAuthenticationAuditLevel="SuccessOrFailure" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Service" name="CustomRoles.Service">
<endpoint address="http://127.0.0.1:8060" binding="webHttpBinding"
bindingConfiguration="webHttp" contract="CustomRoles.IService" />
</service>
</services>
</system.serviceModel>
</configuration>
这就是我调试时看到的。为什么使用 windows 进行身份验证?
凭证屏幕 http://img81.imageshack.us/img81/1289/credentials.gif< /a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在尝试做同样的事情。
我的服务运行良好,我可以通过服务跟踪查看器跟踪对服务的调用。
剩下的唯一问题是我没有收到任何电话回复。我的应用程序冻结,并且调用时出现 TimoutException。这是我的设置:
以及服务模型......`
`
也许通过这段代码,它可以帮助您弄清楚您的代码发生了什么。
如果你发现让我知道一些事情。
I'm trying to do the same thing.
My service is working well, I'm able to trace the call made to the service via the Service Trace Viewer.
The only problem remaining is that I don't receive any answer to the call. My application is freezing and I have a TimoutException on the call. Here's my settings :
And the service model...`
`
Maybe with this piece of code it can help you to figure out what's going on with yours.
If you find let me know something.
我在 WCF 大师班期间就做到了这一点,所以这绝对是可能的。不幸的是,我没有在实践中使用它,现在已经是一年前了......
但是,请尝试 此链接,并查找有关 ASP.NET 会员资格内容的不同下载。这基本上就是培训课程的结果。
I've done this during the WCF Master Class, so it is definitely possible. Unfortunately I did not use this in practice and it's a year ago now...
However, try this link, and look for the different downloads about ASP.NET membership stuff. It is basically the outcome of the training session.
是的,是可能的:
并使用自定义的 UserNamePasswordValidator:
这工作正常!
Yes is possible:
And uses a custom UserNamePasswordValidator:
this works fine!