0

I have a cs file delivered from a vendor with a structure like the following:

public partial class Test : System.Web.UI.Page 
{ 
    public void InsertSignature() 
   { 
        Response.Write("ASDFASDFAF#WRRASDFCAERASDCDSAF"); 
   } 
} 

I am attempting to use the InsertSignature function in a MVC 3 application using the following code

MySample sample = new Test();

sample.InsertSignature();

I'm getting the following HttpException: "Response is not available in this context." Is there anyway that this can work with out modifying the vendor delivered product. I know there are ways to make this work by modifying the file but if at all possible it would be great to avoid doing this.

Thanks in advance.

Travis Stafford
  • 133
  • 1
  • 1
  • 8
  • where is the code that is instantiating that page object - controller, or view? Is it possible to modify or move that code in your project? – Josh E Jun 04 '12 at 15:17
  • I am trying to instantiate the code from a controller. I do have the file and thus the source, however it is vendor delivered and my employer is asking me not to touch the source, so that updating in the future can be a simple file replacement. – Travis Stafford Jun 04 '12 at 15:21
  • Does the vendor code execute in the same (main) thread and does it have access to the HTTP `Response` object? – David R Tribble Jun 04 '12 at 16:24
  • The vendor code is all in the single .cs file. There is just a handfull of public void functions that all make a call to Response.Write(). So, yes I think it's all being exeucted in the main thread. I can alter the call to be Current.Response.Write() and it works. I realize this is a really small modification, however sadly I am being asked to find another way. – Travis Stafford Jun 04 '12 at 16:37

1 Answers1

1

It seems as a known issue (Response is not available in this context)

Just replace

Response.Write("ASDFASDFAF#WRRASDFCAERASDCDSAF"); 

with

HttpContext.Current.Response.Write("ASDFASDFAF#WRRASDFCAERASDCDSAF"); 

and this will do the trick. It doesn't seem as a big change.

UPDATE: If you wish to prevent the code from rewriting with future updates, just rename the method - e.g. from InsertSignature() to InsertSig(). If the file is being updated with the vendor's version, it will simply not compile, and will be clear what the reason is.

Community
  • 1
  • 1
Tisho
  • 8,320
  • 6
  • 44
  • 52
  • I agree it's not a big change at all. It is however a change and I was asked to avoid it if possible. What I am seeing thus far is it is not avoidable. – Travis Stafford Jun 04 '12 at 17:19