asp.net-mvc Owin Identity 城堡 Windsor 如何改写为长尾?

2026-03-30 11:291阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计372个文字,预计阅读时间需要2分钟。

asp.net-mvc Owin Identity 城堡 Windsor 如何改写为长尾?

我在使用Identity和城堡Windsor的经典ASP.NET项目中遇到了OWIN配置问题。问题在于如何管理所有用户的身份信息和如何向登录用户发送cookie等。这需要以下代码:

assembly: OwinStar

我在使用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身份验证)?

asp.net-mvc Owin Identity 城堡 Windsor 如何改写为长尾?

我看过很多关于城堡windsor的文章作为owin dependecy resolver,但它主要是关于自我托管owin.

好的,所以经过近一年的时间我找到了答案: WebApi + Simple Injector + OWIN

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

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

本文共计372个文字,预计阅读时间需要2分钟。

asp.net-mvc Owin Identity 城堡 Windsor 如何改写为长尾?

我在使用Identity和城堡Windsor的经典ASP.NET项目中遇到了OWIN配置问题。问题在于如何管理所有用户的身份信息和如何向登录用户发送cookie等。这需要以下代码:

assembly: OwinStar

我在使用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身份验证)?

asp.net-mvc Owin Identity 城堡 Windsor 如何改写为长尾?

我看过很多关于城堡windsor的文章作为owin dependecy resolver,但它主要是关于自我托管owin.

好的,所以经过近一年的时间我找到了答案: WebApi + Simple Injector + OWIN

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

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