简体   繁体   English

将属性(System.Attribute变体)添加到.aspx页-而不是隐藏代码

[英]Add Attribute (System.Attribute variety) to .aspx page - not the code-behind

I am creating a custom Attribute (extending System.Attribute). 我正在创建一个自定义属性(扩展System.Attribute)。 I know I can put it on another class easily enough by doing the following. 我知道我可以通过执行以下操作轻松地将其放在其他课程上。

[MattsAttribute]
public class SomeClassWhichIsACodeBehind { 

However, I need to be able to test this attribute easily, and putting it in the code-behind would cause a lot of extra effort to get it deployed to an environment which would respond to the behavior of attribute. 但是,我需要能够轻松地测试此属性,并将其放在代码后方将导致大量额外的努力才能将其部署到对属性的行为做出响应的环境中。

What I would like to do: declaratively apply this attribute to the .aspx page itself (which is really just another class that inherits from the code-behind). 我想做的是:以声明的方式将此属性应用于.aspx页本身(实际上只是从后代代码继承的另一个类)。 Is this possible? 这可能吗? If so, what is the proper syntax for doing this? 如果是这样,执行此操作的正确语法是什么?

Check out this post from ScottGu: 查看来自ScottGu的帖子:

http://weblogs.asp.net/scottgu/archive/2005/08/02/421405.aspx http://weblogs.asp.net/scottgu/archive/2005/08/02/421405.aspx

You'll have to extend Page, but it looks about the closest you can come to doing what you want without putting something in a CodeBehind. 您必须扩展Page,但是它看起来最接近您可以做的事而无需在CodeBehind中添加任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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