首先继承自FilterAttribute类同时实现IActionFilter接口,代码如下:













































然后我们建立一个用于处理文件请求的Controller,并应用上我们刚才建立的Filter:
public
class
FilesController:BaseController
{
[AntiOutSiteLink(FileType.Image)]
public ActionResultImage( string file)
{
return Content( " ImageFrom4mvc " );
}
[AntiOutSiteLink(FileType.File)]
public ActionResultFile( string file)
{
return Content( " FileFrom4mvc " );
}
}
{
[AntiOutSiteLink(FileType.Image)]
public ActionResultImage( string file)
{
return Content( " ImageFrom4mvc " );
}
[AntiOutSiteLink(FileType.File)]
public ActionResultFile( string file)
{
return Content( " FileFrom4mvc " );
}
}
简单测试一下: