工作笔记:C#记录重复操作(如顶、踩等)
控制用户对某一条评论只能操作一次,如顶、踩、支持、反对等。
以下代码在实际使用中可能需要修改一下,核心是记录操作者的IP和操作的对象编号到COOKIE中,
在用户操作时,遍历COOKIE中的数据,看是否有对应的记录。
以下代码在实际使用中可能需要修改一下,核心是记录操作者的IP和操作的对象编号到COOKIE中,
在用户操作时,遍历COOKIE中的数据,看是否有对应的记录。
public bool isRepeat(string commentId)
{
string userIp = Request.UserHostAddress;
if (!isCookie())
{
createCookie(commentId, userIp);
return false;
}
else if (!getCookInfo(commentId, userIp))
{
addCookie(commentId);
return false;
}
else
{
return true;
}
}
private bool isCookie()
{
if (Request.Cookies["cook_sustain_oppose"] == null)
return false;
return true;
}
private void createCookie(string commentId, string userIp)
{
HttpCookie cook = new HttpCookie("cook_sustain_oppose");
cook.Values["oId" + commentId] = commentId;
cook.Values["userIp"] = userIp;
Response.Cookies.Add(cook);
}
private void addCookie(string commentId)
{
HttpCookie cook = Request.Cookies["cook_sustain_oppose"];
cook.Values["oId" + commentId] = commentId;
Response.Cookies.Add(cook);
}
private bool getCookInfo(string commentId, string userIp)
{
HttpCookie cook = Request.Cookies["cook_sustain_oppose"];
if (cook.Values["oId" + commentId] == commentId && cook.Values["userIp"] == userIp)
{
return true;
}
return false;
}
- 评论
-
- [使用Ctrl+Enter键可以直接提交]
表情图标
Advertise
Category
Time Counter
离十一还有
Recent Article
- 1.工作笔记:AS3加载外部图片,有加载百分比
- 2.document.documentElement和document.body的区别
- 3.100种增加网站流量的方法
- 4.用div+css模拟表格对角线
- 5.如何做一个好的技术型领导
- 6.苍井空是谁?
- 7."心态"新解
- 8.程序员特有的9个坏习惯
- 9.AS3入门之简单Loading效果
- 10.系统问题:浏览器无法打开png图片
- 11.AS3中以post和get方式提交数据
- 12.defaultTextFormat和setTextFormat()区别
- 13.AS3中超方便地遍历xml
- 14.pv3d中物体常用的移动属性
- 15.开源Flash 3D引擎Papervision3d
- 16.as3 判断鼠标滚轮前滚或后滚
- 17.js:行向上替换滚动效果
- 18.为什么要清净?(禅与佛)
- 19.扩展window.setTimeout方法
- 20.收集2010的搞笑短句
Statistics
Recent Comments
Archive
Links
Support
TOP



