[英]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: 我有一家供应商提供的CS文件,其结构如下:
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 我正在尝试使用以下代码在MVC 3应用程序中使用InsertSignature函数
MySample sample = new Test();
sample.InsertSignature();
I'm getting the following HttpException: "Response is not available in this context." 我收到以下HttpException:“在这种情况下,响应不可用。” 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(). UPDATE :如果希望防止以后的代码重写代码,只需将方法重命名-例如,从InsertSignature()到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. 如果正在使用供应商的版本更新文件,则将不会编译该文件,并且会清楚原因是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.