Is there a way to convert OwinRequest to HttpReque

2019-04-06 08:36发布

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?

标签: c# owin
1条回答
▲ chillily
2楼-- · 2019-04-06 09:01

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;
查看更多
登录 后发表回答