質問

私は、を取るサードパーティライブラリを呼んでいます System.Web.HttpResponse. 。私は持っているようです HttpResponseBase, 、 だがしかし HttpResponse Webフォームのように。

を取得する方法はありますか HttpResponse?使用 MVC 3.

編集 :これをコントローラーメソッドで実行しようとしています。また、ケーシングを修正しました。

役に立ちましたか?

解決

If you need to interact with systems which take the non-mockable types, you can get access to the current HttpContext via the static property System.Web.HttpContext.Current. The HttpResponse is just hanging off of there via the Response property.

他のヒント

In mvc application you can use HttpContext.ApplicationInstance.Response.This helped me for getting the HttpResponse in MVC Application.

No, but your HttpResponseBase is probably an HttpResponseWrapper which contains an HttpResponse inside of it. All the HttpResponse methods are accessible from the HttpResponseBase.

If you want access to the HttpResponse, then you could add a reference to it in HttpContext.Items in your IHttpHandler or somewhere earlier in the ASP.NET lifecycle. The BeginRequest event would be a good point to do this.

Your HttpContext.Items references the same dictionary that HttpContextBase.Items references, so you will have access to all those items in MVC3

To clarify,

It is an HttpResponseWrapper, but there is no public accessor for the HttpResponse. So, there is not a directly accessible reference. To make a directly accessible reference before the framework decides to start giving you the wrapper instead of the underlying reference, create an event handler for HttpApplication.BeginRequest event. Your handler will have a reference to the HttpContext object. Set HttpContext.Items["HttpRequest"] = HttpContext.Request. Then in your controller you will be able to access the HttpRequest reference by RequestContext.HttpContext.Items["HttpRequest"].

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top