Answered by:
convert IOwinContext to System.Web.HttpRequest?

Question
-
User-1038387253 posted
Hello,
I have some Owin middleware filtering calls to my API. A third party module we need to plug in requires an
HttpRequest
as an argument to one of its constructors. I have easy access to all the request data viaIOwinContext
- is there any way to build a System.Web.Request object from this data? I have no control over the third party module, I HAVE to create anHttpRequest
to use it...Thanks in advance!
JB
Tuesday, May 15, 2018 7:05 PM
Answers
-
User283571144 posted
Hi omortis,
It looks to me like this can't be done in a self-hosted Owin environment as `HttpContext` does not exist. Is this correct? Does this mean I will need to move this code base to a setup hosted in IIS?Yes, we couldn't use HttpContext in a self-hosted environment. HttpContext is set by the ASP.Net pipeline, which you won't have if you don't run under IIS/ASP.Net.
The HttpContext is only available in the Web-Hosting mode, in which the HttpControllerHandler creates the request.
Besides, I couldn't understand why want to get the httprequest from iowincontext.
Do you mean you want to send the request to the third party module in the web api?
If this is your requirement, I suggest you could follow below article to create the httpclinet to send the request.
https://stackoverflow.com/a/4015346/7609093
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, May 17, 2018 6:20 AM
All replies
-
User-1038387253 posted
It looks to me like this can't be done in a self-hosted Owin environment as `HttpContext` does not exist. Is this correct? Does this mean I will need to move this code base to a setup hosted in IIS?
Tuesday, May 15, 2018 7:40 PM -
User283571144 posted
Hi omortis,
It looks to me like this can't be done in a self-hosted Owin environment as `HttpContext` does not exist. Is this correct? Does this mean I will need to move this code base to a setup hosted in IIS?Yes, we couldn't use HttpContext in a self-hosted environment. HttpContext is set by the ASP.Net pipeline, which you won't have if you don't run under IIS/ASP.Net.
The HttpContext is only available in the Web-Hosting mode, in which the HttpControllerHandler creates the request.
Besides, I couldn't understand why want to get the httprequest from iowincontext.
Do you mean you want to send the request to the third party module in the web api?
If this is your requirement, I suggest you could follow below article to create the httpclinet to send the request.
https://stackoverflow.com/a/4015346/7609093
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, May 17, 2018 6:20 AM -
User-1038387253 posted
Hi Brando,
I refactored my API to be hosted in IIS. I don't have much of the API surface ported (from python) yet so it only took a day. I need to receive (and parse) a session token from a 3rd party SSO provider and it works fine now.
Thanks!
JB
Thursday, May 17, 2018 12:29 PM