有没有办法将OwinRequest转换为HttpRequestBase?

时间:2014-10-27 16:04:24

标签: c# owin

我正在编写一个Owin中间件,我需要使用一些遗留代码,它使用HttpRequestBase作为方法参数。遗留代码不遵循SOLID,因此无法将其扩展为使用OwinRequest而不是HttpRequestBase

是否有将OwinRequest转换为HttpRequestBase的扩展(或方法)?

1 个答案:

答案 0 :(得分:16)

如果您有权访问请求的IOwinContext,则可以使用此小黑客获取HttpContextBase

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

然后,你只会:

HttpRequestBase httpRequest = httpContext.Request;