简体   繁体   中英

Is there anyway to call a function in a class that inherits from system.web.ui.page from a mvc3 controller?

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.

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 - eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM