如何为 WCF Web 服务实现自定义身份验证机制
我刚刚创建了我的第一个 WCF 服务。现在我想做以下事情:
添加我的自定义身份验证机制,例如,查询数据库的用户表。
使我的服务操作的结果取决于已登录的用户。
我该如何操作?
注意:我已经尝试过谷歌搜索,甚至使用诸如“site:stackoverflow.com”和“site:codeproject.com”之类的站点过滤器,但找不到我需要的东西。
I have just created my first WCF service. Now I would like to do the following:
Add my custom authentication mechanism, e.g., querying a database's user table.
Make the results of my service's operations dependent on the user that has logged in.
How do I do that?
NOTE: I have already tried googling, even using site filters such as "site:stackoverflow.com" and "site:codeproject.com", but couldn't find what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您好,
根据项目的规模,下面链接中概述的一些解决方案可能有点过分,但是,请随意查看。
WCF 安全实践
Greetings,
Depending on the size of the project, some of the solutions outlined in the link below may be overkill, however, feel free to take a look.
WCF Security Practices
创建自定义 UserNamePasswordValidator 并重写 Validate 方法。
http://msdn.microsoft.com/en-us/library/aa702565.aspx
在您的服务实现中,您将可以访问“OperationContext.Current.ServiceSecurityContext.PrimaryIdentity”,这是经过身份验证的用户。
Create a custom UserNamePasswordValidator and override the Validate method.
http://msdn.microsoft.com/en-us/library/aa702565.aspx
Inside your service implementation you'll have access to "OperationContext.Current.ServiceSecurityContext.PrimaryIdentity" which is the user that was authenticated.