Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2014/1/16 9:31:07
利用Cache限制页面频繁请求(最少要等N秒)_[Asp.Net教程]

利用Cache限制页面频繁请求(最少要等N秒)_[Asp.Net教程]

string ip = WebUtil.GetIPString();
if (path.StartsWith("/article/download.aspx")) //在Application_BeginRequest 判断是否需要限制的页,如果是特定页面在Page_Load中不用判断了。
{
string key = "请求时间限制_" + ip;
if (Context.Cache[key] == null)
{
Context.Cache.Insert(key, 1, null,
Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 10));//10秒限制
}
else
{
Visitor visitor = Visitor.Current;
if (!visitor.HasPermission(Permissions.Sponser)) // 赞助用户不作限制
{


nextTitle = "你要查看的页面";
nextUrl = Request.RawUrl;
message = "对不起,你的点击或刷新页面太快,服务器无法完成请求。请点击或刷新页面之间的时间不要小于10秒。赞助用户无此限制。谢谢!";
Util.RedirectToInfoPage(InfoIcon.Stop, message, nextTitle, nextUrl);
return;

}
}
}


来源:阿良.NET







If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759