在aspx页面中实现接口
由于超出本讨论范围的原因(比如将一个 aspx 页面复制到一个目录,这样我们就不必进行新的构建),我们希望在 aspx 页面中实现一个接口。假设该页面是 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 类型的页面,我们希望以不同的方式处理它。
这怎么办?
for reasons beyond the scope of this discussion (say xcopy an aspx page to a directory, so that we dont have to get a new build out) , we would like to implement an interface in an aspx page.Say, if the page is myPage.aspx, it is usually your class in the codebehind mypage.aspx.cs which implements the interface. When I do something like this
<%@ Page Language="C#" AutoEventWireup="true" Inherits="ICustomInterface" %>
I get an error
Parser Error Message: 'ICustomInterface' is not allowed here because it does not extend class 'System.Web.UI.Page'.
How ever, when not specifying an Inherits
attribute the page does not throw an error. So by default, when we do not specify an Inherits
attribute, the page inherits from System.web.UI.Page
?
We are using VS2008 web application project and are not precompiling the aspx pages. We would like to intercept the request to this page in the HTTPModule (begin request) and if the request is to a page of type ICustomInterface we would like to process it differently.
How can this be done ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为
Inherits
参数需要基类,而不是接口。您也许可以尝试创建一个辅助类,它继承自 System.Web.UI.Page 并实现您需要的接口。
虽然,我完全只是猜测。
It could be because the
Inherits
parameter is expecting a base class, not an interface.You could perhaps try creating a secondary class, which inherits from
System.Web.UI.Page
and implements the interface you need.Although, I'm totally just guessing at this.