【问题标题】:Castle windsor with owin and Identity温莎城堡与 owin 和 Identity
【发布时间】:2016-11-21 06:39:56
【问题描述】:

我在使用 Identity 和 Castle Windsor 的典型 asp.net 项目中的 owin 配置存在问题。 问题是我真的很喜欢 identity 和 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 管道集成?或者,至少,如何在没有 owin 的情况下将 CookieAuthentication 与我的自定义 ApplicationSignInManager 一起使用(并且无需我自己重写整个 cookie 身份验证)?

我看过很多将温莎城堡作为 owin 依赖解析器的文章,但主要是关于自托管 owin。

【问题讨论】:

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


    【解决方案1】:

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

    有张贴此帖:https://simpleinjector.codeplex.com/discussions/539965 然后它在这里引导:Does SimpleInjector's WebAPIRequest lifetime include Message Handlers?

    我认为这 3 个问题/答案加起来让我很满意。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多