城堡温莎与owin和身份

时间:2016-06-09 23:03:49

标签: asp.net-mvc asp.net-identity owin castle-windsor

我在使用Identity和城堡windsor的典型asp.net项目中遇到owin配置问题。 问题是我真的喜欢身份和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。

1 个答案:

答案 0 :(得分:0)

好的,差不多一年后我在这里找到答案:WebApi + Simple Injector + OWIN

发布了这篇文章:https://simpleinjector.codeplex.com/discussions/539965 然后它在这里引导:Does SimpleInjector's WebAPIRequest lifetime include Message Handlers?

我认为这三个问题/答案的结合让我满意。