在MVC 6中使用GetOwinContext

6
我正在使用 Membership Reboot 在我的 Asp.Net5 MVC 6 网站应用程序中管理我的身份验证、登录等。
我正在尝试将 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类使用它)?

我正在处理一些身份验证问题,它使用Owin工作,但在新的ASP.NET Core环境中尚不被支持,并且我遇到了同样的问题。您找到任何方法使旧代码与新代码兼容了吗?没有访问Owin上下文时,无法通过控制器使用启动时在Owin上下文中配置的方式触发退出登录。 - Matt Sanders
我有同样的问题。我需要一个Owin上下文来实际注销用户。有什么解决方法吗? - Skorunka František
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接