【问题标题】:implementing interface in an aspx page在aspx页面中实现接口
【发布时间】:2011-01-14 04:56:06
【问题描述】:

出于本讨论范围之外的原因(比如将一个 aspx 页面复制到一个目录,这样我们就不必重新构建),我们希望在一个 aspx 页面中实现一个接口。比如说,如果page 是 myPage.aspx,它通常是代码隐藏 mypage.aspx.cs 中实现接口的类。当我做这样的事情时

<%@ Page Language="C#" AutoEventWireup="true"  Inherits="ICustomInterface" %>

我收到一个错误

Parser Error Message: 'ICustomInterface' is not allowed here because it does not extend class 'System.Web.UI.Page'.

但是,当不指定 Inherits 属性时,页面不会引发错误。所以默认情况下,当我们不指定Inherits属性时,页面继承自System.web.UI.Page

我们正在使用 VS2008 Web 应用程序项目并且没有预编译 aspx 页面。我们希望在 HTTPModule(开始请求)中截获对该页面的请求,如果该请求是对 ICustomInterface 类型的页面的请求,我们希望以不同的方式处理它。

如何做到这一点?

【问题讨论】:

    标签: asp.net interface implementation httpmodule web-application-project


    【解决方案1】:

    这可能是因为Inherits 参数需要一个基类,而不是一个接口。

    您或许可以尝试创建一个从 System.Web.UI.Page 继承并实现您需要的接口的辅助类。

    虽然,我完全只是在猜测。

    【讨论】:

    • +1 好的解决方案;实际上可以这样实现多个接口
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多