Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a reference to an HttpResponse in ASP.NET MVC?

I'm calling a third-party library that takes a System.Web.HttpResponse. I see I have a HttpResponseBase, but not HttpResponse like in web forms.

Is there a way to get the HttpResponse? Using MVC 3.

[Edit] : I'm trying to do this in a controller method. Also corrected casing.

like image 877
Mike Hildner Avatar asked Mar 15 '11 14:03

Mike Hildner


2 Answers

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.

like image 141
Levi Avatar answered Sep 23 '22 11:09

Levi


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

like image 26
akky Avatar answered Sep 24 '22 11:09

akky