我正在使用 Membership Reboot 在我的 Asp.Net5 MVC 6 网站应用程序中管理我的身份验证、登录等。
我正在尝试将 MR 的 OwinAuthenticationService 作为实现注入到我的控制器中,以便与
示例代码涉及使用以下 Autofac 注册方式来注入
在MVC5中,可以使用
我看到访问
在MVC6中是否有一种方法可以获取当前的Owin上下文,或者当前的Owin环境字典(因为
我正在尝试将 MR 的 OwinAuthenticationService 作为实现注入到我的控制器中,以便与
IAuthenticationService
接口一起使用。示例代码涉及使用以下 Autofac 注册方式来注入
IAuthenticationService
:builder.Register(ctx=>HttpContext.Current.GetOwinContext()).As<IOwinContext>();
builder.Register<IAuthenticationService>(ctx =>
{
var owin = ctx.Resolve<IOwinContext>();
return new OwinAuthenticationService(
MembershipRebootOwinConstants.AuthenticationType,
ctx.Resolve<IUserAccountService>(),
owin.Environment);
}).InstancePerLifetimeScope();
在MVC5中,可以使用
Microsoft.Owin.Host.SystemWeb
程序集中的扩展方法HttpContext.Current.GetOwinContext()
。然而,在MVC6中不再使用该程序集,因此HttpContext.Current
无法解析。我看到访问
HttpContext
的新方法是使用新的IHttpContextAccessor
接口,但这并不能解决获取Owin上下文的问题。在MVC6中是否有一种方法可以获取当前的Owin上下文,或者当前的Owin环境字典(因为
OwinAuthenticationService
类使用它)?