使用ASP.net Identity 2.0框架在WCF中验证用户 [英] Validating a user in WCF using ASP.net Identity 2.0 Framework
问题描述
我已经通过简单扩展新的asp.net身份框架2.0来构建了一个自定义Identity.Models框架,这样我就可以将用户名和其他相关用户数据存储在我的自定义数据库中,而不是生成的默认实体数据库中.工作正常.
I have built a custom Identity.Models framework by simply extending the new asp.net identity framework 2.0 so that I can store the username and other relevant user data in my custom database instead of the default entity database which gets generated and it is working fine.
现在,我正在从此处构建WCF服务,以验证这些用户的身份并利用asp.net Identity 2.0功能,但无法这样做.
Now I am building a WCF service from where I would like to authenticate these users and leverage the asp.net identity 2.0 functionalities , but unable to do so.
在WCF服务中,我创建了一个新的Validator类,扩展了UsernamePasswordValidator,但未按预期工作.
In my WCF service I made a new Validator class extending UsernamePasswordValidator but it is not working as expected.
public class IdentityValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
using (var context = new MyIdentityDbContext())
{
using (var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)))
{
var user = userManager.Find(userName, password);
if (user == null)
{
var msg = String.Format("Unknown Username {0} or incorrect password {1}", userName, password);
Trace.TraceWarning(msg);
throw new FaultException(msg);
}
}
}
}
}
任何建议将不胜感激.
推荐答案
您已经差不多了,但是,您还需要一步来通过引入服务行为(通常是在配置中)来告知WCF服务行为良好.有关更多详细信息,请阅读
You are almost there, however, you need one more step to tell the WCF service to be well behaved through introducing service behavior, generally in config. For more details, please read
这篇关于使用ASP.net Identity 2.0框架在WCF中验证用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!