0

In WebApi I used to do this on my BaseApiController:

Request.GetOwinContext().Response.Headers.Add("X-Pagination", new[] { Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader) });

I'm converting to ASP.NET v5, and I get the error:

HttpRequest does not contain a definition for GetOwinContext

Any pointers?

Sean
  • 14,359
  • 13
  • 74
  • 124
  • http://stackoverflow.com/questions/22598567/asp-net-webapi-cant-find-request-getowincontext check this link – Prashant Nov 03 '15 at 21:31
  • I tried that and it doesn't work. I don't think it's relevant to ASP.NET v5 / MVC6? – Sean Nov 03 '15 at 21:36
  • Try this. OwinContext owinContext = (OwinContext)Request.Properties["MS_OwinContext"]; – Prashant Nov 03 '15 at 21:41
  • I shouldn't have to do that, surely? Every time I want to do something like `GetUserManager` I have to cast the context? – Sean Nov 03 '15 at 21:48
  • we use owin hosting for my webapi , i did't find a easy way of retrieving the owin context from the request. we this "OwinContext owinContext = (OwinContext)Request.Properties["MS_OwinContext"];". – Prashant Nov 03 '15 at 22:35
  • Ok, but the MVC6 Request object doesn't have a Properties property...? – Sean Nov 04 '15 at 05:50

1 Answers1

1

ASP.NET 5 is not based on OWIN, so don't expect GetOwinContext() to work.

Your code can be easily adapted to the new HttpResponse primitive:

Response.Headers["X-Pagination"] = JsonConvert.SerializeObject(paginationHeader);
Kévin Chalet
  • 39,509
  • 7
  • 121
  • 131
  • Can I not use OWIN with ASP.NET 5? I wanted a lightweight api, but with V5, is that not possible? – Sean Nov 05 '15 at 06:06
  • MVC 6 doesn't use OWIN. It directly relies on the new `HttpContext`/`HttpRequest`/`HttpResponse` primitives exposed by ASP.NET 5. – Kévin Chalet Nov 05 '15 at 11:25
  • Ok, then I'm really lost. Is that the end of the road for OWIN? I thought it was the new, lean, composable way of building web systems. I struggled to get my system to use it and now it seems I backed the wrong horse? – Sean Nov 05 '15 at 12:53
  • No, OWIN is still supported via an adapter, but ASP.NET 5 is not-OWIN-based. Anyway, you have no reason to use OWIN when working with MVC 6. – Kévin Chalet Nov 05 '15 at 18:02