本文介绍了如何将HttpRequest转换为HttpRequestBase对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与此相反: 如何将HttpRequestBase转换为HttpRequest对象?

My problem is the opposite of this: How do I convert an HttpRequestBase into an HttpRequest object?

在我的ASP.NET MVC应用程序中,我有一种方法被许多接收HttpRequestBase作为参数的控制器使用.

In my ASP.NET MVC application I have a method used by many controllers that receive an HttpRequestBase as argument.

现在,我必须从另一个方法(不是动作(它是nhibernate拦截器))中调用该方法.在第二种方法中,我可以访问HttpContext.Current.Request,即HttpRequest,并且无法将其强制转换为HttpRequestBase(由于命名原因,我认为它是可能的.).

Now I have to call that method from another method, that is not an action (it's an nhibernate interceptor). In this second method I could access HttpContext.Current.Request, that is a HttpRequest and I cannot cast it to HttpRequestBase (I thought it was possibile due to the naming ...).

有人知道这些课程的关系如何,如何解决我的问题?谢谢.

Does someone know in what relationship are this classes and how can I solve my problem?Thank you.

推荐答案

您需要将HttpRequest包装在HttpRequestWrapper中:

var wrapper = new HttpRequestWrapper(httpRequest);

HttpRequestWrapper继承自HttpRequestBase.

这篇关于如何将HttpRequest转换为HttpRequestBase对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 19:32