All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

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

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/16 9:31:07 Browse times: 327 Comment times: 0

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


Head photo

Go homepage
Upload pictures
Write articles

利用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





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.