我在我的Asp.Net5 MVC 6 Web应用程序中使用Membership Reboot来管理我的身份,登录等 .
我'm trying to get MR' s 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中,这可以作为 HttpContext.Current.GetOwinContext()
作为 Microsoft.Owin.Host.SystemWeb
程序集中的扩展方法 . 但是,此程序集不再在MVC6中使用,因此 HttpContext.Current
无法解析 .
我已经看到访问 HttpContext
的新方法是使用新的 IHttpContextAccessor
接口,但这并没有解决获取Owin上下文的问题 .
有没有办法在MVC6中获取当前的Owin上下文,或者当前的Owin环境字典(因为这是 OwinAuthenticationService
类使用的)?
1 回答
OWIN失去了在ASP.NET Core 1.0(又名ASP.NET 5)中的地位,
https://docs.asp.net/en/latest/fundamentals/owin.html
但您可以在上面的页面上找到所有信息 . 似乎OWIN背景已经消失 .