ASP.NET Identity 2 - injecting ISecureDataFormat<>

对着背影说爱祢 提交于 2019-12-10 11:19:28

问题


I'm having same issue described here with no answer, just using Unity.

I'm trying to register ISecureDataFormat<> in the lastest VS2013 (update 2) SPA/Web Api template.

I've tried

container.RegisterType(typeof(ISecureDataFormat<>), typeof(SecureDataFormat<>));
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, TicketDataFormat>();

It "works" but not really because then it complains about the next depenedency in that tree, IDataSerializer... and then the next IDataProtector, for which I found no implementation.


回答1:


I solved the following error in SimpleInjector with the following mappings

container.Register<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.Register<IDataProtector>(() => new DpapiDataProtectionProvider().Create("ASP.NET Identity"));

To figure out what serializer was used I noticed that the ISecureDataFormat generic parameter in the AccountsController was a AuthenticationTicket type. In checking the IDataSerializer namespace the TicketSerializer implements IDataSerializer.

To figure out IDataProtector I again looked in the IDataProtector namespace and found the implementation of the IDataProtectionProvider.



来源:https://stackoverflow.com/questions/24375790/asp-net-identity-2-injecting-isecuredataformat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!