我在使用Identity和城堡windsor的典型asp.net项目中遇到owin配置问题. 事情是我真的喜欢身份和owin如何管理所有用户的东西,如向登录用户发送cookie等等,但它需要以下代码: [assembly: OwinStar
事情是我真的喜欢身份和owin如何管理所有用户的东西,如向登录用户发送cookie等等,但它需要以下代码:
[assembly: OwinStartupAttribute(typeof(OwinStartUp.Startup))] namespace OwinStartUp { public partial class Startup { public void Configuration(IAppBuilder app) { app.CreatePerOwinContext(DbOwinHelper.CreateDbContext); app.CreatePerOwinContext<ApplicationUserManager>(DbOwinHelper.CreateUserManager); app.CreatePerOwinContext<ApplicationSignInManager>(DbOwinHelper.CreateSignInManager); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, MyIdentityUser, Guid>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager), getUserIdCallback: (user) => Guid.Parse(user.GetUserId())) } }); } }
}
所以在例如控制器我必须写这个:
var signInManager = HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
而不是这(我喜欢)
var signinmanager = container.Resolve<ISignInManager<IMyIdentityUser>>();
或至少
var signinmanager = container.Resolve<ApplicationSignInManager>();
我怎样才能将windsor与owin管道整合?或者,至少,如何将CookieAuthentication与我的自定义ApplicationSignInManager一起使用而不使用owin(并且没有重写我自己的整个cookie身份验证)?
我看过很多关于城堡windsor的文章作为owin dependecy resolver,但它主要是关于自我托管owin.
好的,所以经过近一年的时间我找到了答案: WebApi + Simple Injector + OWIN发表这篇文章:https://simpleinjector.codeplex.com/discussions/539965
然后它在这里引导:Does SimpleInjector’s WebAPIRequest lifetime include Message Handlers?
我认为这三个问题/答案的结合让我满意.