语法内容:
namespace SunSoft.MVC
{
[AttributeUsage(AttributeTargets.Method,AllowMultiple = false,Inherited = false)]
public class ActionAttribute
{
}
}
一般,这个标记放在类的上面
AttributeUsage:指定这个属性的使用说明。
AttributeTargets:指定这个属性适用的对象(枚举还有很多,如下图)
AllowMultiple:该值指示能否为一个程序元素指定多个指示属性实例。(参见:http://msdn.microsoft.com/zh-cn/library/system.attributeusageattribute.allowmultiple(VS.80).aspx)
Inherited:该值指示指示的属性能否由派生类和重写成员继承(http://msdn.microsoft.com/zh-cn/library/system.attributeusageattribute.inherited(v=vs.80).aspx)。
然后需要处理HTTP请求,实现IHttpHandle接口(请引用System.Web命名空间)
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace SunSoft.MVC
{
internal class ActionHandler:IHttpHandler
{
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest(HttpContext context)
{
throw new NotImplementedException();
}
}
}
这里的:
IsReusable:是设置指示其他请求是否可以使用 IHttpHandler 实例(参见【大叔手记(9)】:http://www.cnblogs.com/TomXu/archive/2011/12/17/2288579.html)。如果线程非安全,建议返回否(false)
ProcessRequest:是一个需要实现的方法,这个方法处理HTTP请求