0

的Web API 2的AccountController我使用ASP.NET 2.2的身份在Web API 2項目,但我不確定如何連接起來使用AutofacAccountControllerISecureDataFormat<AuthenticationTicket>依賴。注漿ISecureDataFormat使用Autofac

我嘗試這樣做:

builder.RegisterType<ISecureDataFormat<AuthenticationTicket>>() 
     .As<TicketDataFo‌​rmat>(); 

,並收到錯誤:

The type 'Microsoft.Owin.Security.ISecureDataFormat`1[Microsoft.Owin.Security.Authenticat‌​ionTicket]' is not assignable to service 'Microsoft.Owin.Security.DataHandler.TicketDataFormat'

的,我碰到的問題似乎都不使用ASP.NET身份的最新穩定版本一起使用。

任何幫助,非常感謝。

+0

您能與我們分享您嘗試過什麼,錯誤信息是什麼? –

+0

我試過這個:'builder.RegisterType >()。作爲();'並得到錯誤:類型'Microsoft.Owin.Security.ISecureDataFormat'1 [Microsoft.Owin.Security.AuthenticationTicket ]'不能分配給服務'Microsoft.Owin.Security.DataHandler.TicketDataFormat'。 –

回答

5

你必須做相反的事情。用Autofac您註冊一個類型作爲服務。

builder.RegisterType<TicketDataFo‌​rmat>() 
     .As<ISecureDataFormat<AuthenticationTicket>>(); 

,並根據this answer,看來你還需要註冊一個IDataSerializer<AuthenticationTicket>IDataProtector實現。

builder.RegisterType<TicketSerializer>() 
     .As<IDataSerializer<AuthenticationTicket>>(); 
builder.Register(c => new DpapiDataProtectionProvider().Create("ASP.NET Identity")) 
     .As<IDataProtector>();