问题描述
我写了一块Owin中间件,在这里我需要使用一些旧的代码,它使用HttpRequestBase作为方法参数的。所以这是不可能把它扩大,而不是使用HttpRequestBase
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
OwinRequest遗留代码不遵循SOLID是否有一个扩展名(或方式)到OwinRequest转换成HttpRequestBase ?
Is there an extension (or a way) to convert an OwinRequest into a HttpRequestBase?
推荐答案
如果您有机会获得 IOwinContext
的要求,你可以使用这个小黑客获得 HttpContextBase
:
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;
这篇关于有没有一种方法来OwinRequest转换为HttpRequestBase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!