。先来看一段c# 代码

 for(int i=0,i<10000,i++)

{

webclient client=new webclient();

client.Downloadstring(http://www.dddddd.com/default.aspx);

}

若果你调用2次后你得不到任何响应了,并不是你服务器死了,而是服务器拒绝了你的请求。、

asp.net 缓存中记录了某个使用者的ip和每个ip 的ip请求数目。在计数器预定值的限度内,会拒绝后来持续时间的再次请求。

再看一个actionValidator 类。

public static class ActionValidator

{

  private const DURATION=10 ;//10分钟

  public enum ActionTypeEnum

 {

   FirstVist=100,

  revisti=1000;

  postback=5000;

  AddNewwidget=100,

 AddNewPage=100,

  }

}

命名一个IsValid 的静态方法来做些检测。 请求通过则返回true,
如果决绝则false,一旦false , 就调用Request.End(),或者切换页面的方式在另外个页面显示错误信息。

public static bool IsValid(actionTypeEnum actionType)

{

 HttpContext context =HttpContext.Current;

if(context.Request.Brower.Crawler)

return false;

string key=actiontype.Tosting()+context.Request.UserHostAddress;

var hit=(HitInfor)(context.Cache[key])?? new HitInfor());

if(hit.hits>(int)actionType) return false;

else hit.Hits++;

if(hit.Hits==1)

{

  context.Cache.Add(key,hit,null,DateTime.Now.AddMinutes(DURATION),system.web.Cache.Cache.NoLidExpiration,System.web.Caching.CacheItemPriority.Normal,null);

return true;

}

}

使用方法很简单

protected override void onInit(EventArgs e)

{

  base.oninit(e);

 if(!base.IspostBack)

{

  if(profile.isFirstVist)

{

  if(!ActionValiator.IsValid(ActionValidator.ActionTypeEnum.FirstVist))

 Response.End();

 else

{

    if(!ActionValidator.IsValid(ActionValidator.ActionTypeEnum.ReVist))

Response.End();

}

}

}

else

{

    if(!ActionValidator.IsValid(ActionValidator.ActionTypeEnum.PostBack))

Response.end();

}

}

当然,你也可以用硬件防火墙,但是它只能保证的仅仅是网络级别的。但是防火墙没有提供分析数据包功能,以判断是不是在一个特殊ip在没有cookies 的情况下,恶意点击站点的功能,这些都是硬件防火墙不能做到的。