简体   繁体   English

无论如何,在从mvc3控制器继承自system.web.ui.page的类中调用函数吗?

[英]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.

相关问题 一个类可以继承System.Web.UI.Page和System.Web.UI.UserControl吗? - Can a class inherit from both System.Web.UI.Page and System.Web.UI.UserControl? 从不扩展System.Web.UI.Page的类中获取System.Web.HttpResponse - Get System.Web.HttpResponse from a class which does not extend System.Web.UI.Page 从Custom System.Web.UI.Page类设置页面标题 - Set Page Title from Custom System.Web.UI.Page class MasterPage需要来自System.Web.UI.Page派生的抽象泛型类的属性 - MasterPage needs property from abstract generic class derived from System.Web.UI.Page 从System.Web.UI.Page继承时,Session为null - Session is null when inherit from System.Web.UI.Page 从 HttpContext 获取当前 System.Web.UI.Page? - Get current System.Web.UI.Page from HttpContext? 在.Net中,是否可以在不从System.Web.UI.Page继承的类中使用Response.Write - In .Net, is it possible to use Response.Write in a class that does not inherit from System.Web.UI.Page 在ASP.NET MVC5中等效的系统类(System.Web.UI.Page)属性(httpresponse) - system class(System.Web.UI.Page) property(httpresponse) equivalent in asp.net mvc5 错误 - 类不扩展 System.Web.UI.Page - Error - class does not extend System.Web.UI.Page 在尝试发出“成功”消息时无法从'.Controllers.AccountController'转换为'System.Web.UI.Page' - Cannot convert from '.Controllers.AccountController' to 'System.Web.UI.Page' when trying to make “success” message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM