0

we are using AspNetCore.Http with MyController : Controller. How do I get Get OwinContext this.Request.GetOwinContext(); doesnt work.

'HttpRequest' does not contain a definition for 'GetOwinContext' and the best extension method overload 'OwinHttpRequestMessageExtensions.GetOwinContext(HttpRequestMessage)' requires a receiver of type 'HttpRequestMessage'

user1324887
  • 632
  • 3
  • 11
  • 32

1 Answers1

1

ASP.NET Core:

OWIN allows web apps to be decoupled from web servers. It defines a standard way for middleware to be used in a pipeline to handle requests and associated responses. ASP.NET Core applications and middleware can interoperate with OWIN-based applications, servers, and middleware.

OWIN provides a decoupling layer that allows two frameworks with disparate object models to be used together.

enter image description here

The Microsoft.AspNetCore.Owin package provides two adapter implementations:

  • ASP.NET Core to OWIN
  • OWIN to ASP.NET Core

This allows ASP.NET Core to be hosted on top of an OWIN compatible server/host or for other OWIN compatible components to be run on top of ASP.NET Core.


Note:

Using these adapters comes with a performance cost. Apps using only ASP.NET Core components shouldn't use the Microsoft.AspNetCore.Owin package or adapters.

Michael Wang
  • 3,782
  • 1
  • 5
  • 15
  • How do I get owincontext or owin's IDictionary in this usecase. It's not shared in docs either. – user1324887 Mar 24 '21 at 07:40
  • You could only run OWIN middleware in the ASP.NET Core pipeline but not in ASP.NET Core controller. – Michael Wang Mar 24 '21 at 07:52
  • `GetOwinContext()` is a part of the `System.Web.Mvc` assembly using the `ASP.NET` not `ASP.NET Core`. You could use `HttpContext.Authentication` in `ASP.NET Core` apps. – Michael Wang Mar 24 '21 at 07:58
  • I am trying to do something with websockets so not really sure how `HttpContext.Authentication` will be helpful. I need to access `IDictionary` object of Owin. Even in pipelines, how do I access the owin context or `IDictionary` in asp.net core? – user1324887 Mar 24 '21 at 16:56
  • Check [Microsoft.AspNetCore.Owin.OwinEnvironment](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.owin.owinenvironment?view=aspnetcore-5.0). Here is a demo of [OwinSample](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/owin/sample/src/OwinSample/Startup.cs) – Michael Wang Mar 25 '21 at 02:44