简体   繁体   English

ASP.NET MVC 5-WCF中的IdentityUser?

[英]ASP.NET MVC 5 - IdentityUser in WCF?

I am currently writing a WCF service that will use ASP.NET Identity to perform all membership and claims related stuff. 我目前正在编写一个WCF服务,该服务将使用ASP.NET身份执行所有成员资格和声明相关的工作。 (That is, authentication, registration, and all will be performed by calling this WCF) (也就是说,身份验证,注册以及所有操作都将通过调用此WCF来执行)

[DataContract(IsReference=true)]
public class ApplicationUser: IdentityUser
{
    [DataMember]
    public string FirstName { get; set; }
    [DataMember]
    public string LastName { get; set; }
    [DataMember]
    public string Email { get; set; }
}

The problem is that "IdentityUser" is a class in Microsoft.Aspnet.Identity.Core.Entityframework assembly, and this class is not marked with DataContract attribute. 问题是“ IdentityUser”是Microsoft.Aspnet.Identity.Core.Entityframework程序集中的类,并且该类未标记有DataContract属性。 I am writing an operation in my WCF service to return ApplicationUser to the calling website. 我在WCF服务中编写了一个操作,以将ApplicationUser返回到调用网站。

Any idea of how to achieve this? 关于如何实现这一目标的任何想法?

Create a data transfer object (DTO) that has a data contract that has the same properties as the ApplicationUser class. 创建一个数据传输对象(DTO),该对象的数据协定的属性与ApplicationUser类相同。 You will have to do a transformation from your DTO to the ApplicationUser, and the other way. 您将不得不执行从DTO到ApplicationUser的转换。 Use AutoMapper to do the transformation. 使用AutoMapper进行转换。

Personally I do not see any real benefit of putting security behind a WCF web service. 我个人看不到将安全性放在WCF Web服务背后的任何真正好处。 A network hop and serialization/deserialization on every authorization is really going to dog your web application. 在每个授权上进行网络跳和序列化/反序列化确实会困扰您的Web应用程序。

It is a good idea to separate it into a different layer, but that layer does not have be to be a web service. 将其分为不同的层是一个好主意,但是该层不必是Web服务。 Take a look at SimpleSecurity . 看一下SimpleSecurity It provides a layer over ASP.NET Identity and demonstrates how to customize it for email confirmation and other enhanced functionality. 它提供了ASP.NET Identity之上的一层,并演示了如何自定义它以用于电子邮件确认和其他增强功能。 Your authorization functionality is not a good item to distribute because it is hit for every request from the web client. 授权功能不是一个很好的分发项目,因为Web客户端的每个请求都将其击中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM