GetOwinContext in MVC 6

I use Membership Reboot in my Asp.Net5 MVC 6 web application to manage my identity, logins, etc.

I am trying to get an MR OwinAuthenticationService , working as an implementation for the IAuthenticationService interface that I enter in my controllers.

The sample for this includes an IAuthenticationService injection, depending on the following Autofac registration:

 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(); 

In MVC5, this would be great if HttpContext.Current.GetOwinContext() as an extension method in the Microsoft.Owin.Host.SystemWeb assembly. However, this assembly is no longer used in MVC6, so HttpContext.Current not allowed.

I saw that the new way to access HttpContext uses the new IHttpContextAccessor interface, but this does not solve the problem of getting Owin context.

Is there a way to get the current Owin context in MVC6 or the current Owin environment dictionary (from what uses the OwinAuthenticationService class)?

+6
source share
1 answer

OWIN has lost its position in ASP.NET Core 1.0 (aka ASP.NET 5),

https://docs.asp.net/en/latest/fundamentals/owin.html

But you can find all the information on the above page. The OWIN context seems to be gone.

0
source

All Articles