城堡温莎与 owin 和身份
Castle windsor with owin and Identity
我在使用 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 身份验证)?
我看过很多文章将 castle windsor 作为 owin 依赖解析器,但主要是关于自托管 owin。
好的,差不多一年后我在这里找到了答案:WebApi + Simple Injector + OWIN
post编辑了这个post:https://simpleinjector.codeplex.com/discussions/539965
然后它引导到这里:Does SimpleInjector's WebAPIRequest lifetime include Message Handlers?
我认为这 3 个 questions/answers 加起来让我很满意。
我在使用 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 身份验证)?
我看过很多文章将 castle windsor 作为 owin 依赖解析器,但主要是关于自托管 owin。
好的,差不多一年后我在这里找到了答案:WebApi + Simple Injector + OWIN
post编辑了这个post:https://simpleinjector.codeplex.com/discussions/539965 然后它引导到这里:Does SimpleInjector's WebAPIRequest lifetime include Message Handlers?
我认为这 3 个 questions/answers 加起来让我很满意。