Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to convert OwinRequest to HttpRequestBase?

Tags:

c#

owin

I'm writing a piece of Owin Middleware, where I need to use some legacy code, which uses HttpRequestBase as method argument. The legacy code does not follow SOLID so It's impossible to extend it to use OwinRequest instead of HttpRequestBase

Is there an extension (or a way) to convert an OwinRequest into a HttpRequestBase?

like image 865
Maciek Avatar asked Oct 27 '14 16:10

Maciek


1 Answers

If you have access to the IOwinContext of the request, you can use this little hack to get the HttpContextBase:

HttpContextBase httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName);

And then, you would just:

HttpRequestBase httpRequest = httpContext.Request;
like image 169
Matias Cicero Avatar answered Oct 26 '22 04:10

Matias Cicero