如何在ASP.NET中进行计数? [英] How to hit counts in ASP.NET?

查看:90
本文介绍了如何在ASP.NET中进行计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是经典asp中的代码:

This is the code in classic asp:

set con=Server.CreateObject("ADODB.Connection")
con.Open strcon
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM category where news_allow=1",con,0,1 
		
do while not rs.eof
	news_visit=0
	set rst=Server.CreateObject("ADODB.Recordset")
	rst.Open "SELECT news_visit FROM news_list where news_ID="&rs("news_ID")&" and news_status=1",con,0,1 
				
	do while not rst.eof
        news_visit=rst("news_visit")+news_visit
	rst.MoveNext
        loop	
set rst=nothing


该页面包含新闻类别,在该类别下它显示那里有多少新闻,以及击中该类别新闻的次数.我想要C#中的这段代码.如果用户单击类别下的新闻,则news_visit计数器为+1.

请任何人可以帮助我该怎么做.

在此先感谢


The page contain news category and under the category it display how many news are there and how many times hit this category news. I want this code in C#. If user click the news under the category then the news_visit counter is +1.

Please any one can help me how can I do this.

Thanks in advance

推荐答案

虽然您所提出的问题有些含糊,但我想我可以提供帮助.

当您要在ASP.NET中的整个应用程序中存储匹配时,应使用应用程序级变量.它们的工作方式与会话变量相同,只是(您猜对了)它们不会在会话结束时过期.但是,当应用程序重新启动/终止时,它们将重置.

如果您不关心数字是否在应用程序重新启动时重置,请使用应用程序级变量.将事件处理程序附加到链接按钮,按钮或您选择使用的任何按钮的click事件上,这将使应用程序变量增加一.这是有关应用程序级变量的教程: ^ ]

如果您确实担心数字是否在应用程序重新启动时重置(或者如果您的应用程序将要在多个服务器上运行),那么您应该采用与前面提到的相同的方法,但不要使用应用程序状态来存储您的值,而应该使用数据库推/拉变量的系统.

希望这会有所帮助

-Moarcodeplz
While the question you are asking is somewhat vague, I think I may be able to help.

When you want to store hits across your entire application in ASP.NET, you should use an application level variable. These work the same way as session variables except (you guessed it) they don''t expire at the end of a session. They WILL however reset when the application is restarted/terminated.

If you do not care if the numbers reset upon an application restart, then use an application level variable. Attach an event handler to the click event of the linkbutton, button, or whatever button you choose to use that will increment the application variable by one. Here is a tutorial on application level variables: http://weblogs.asp.net/albertpascual/archive/2010/03/01/difference-between-asp-net-sessions-application-variables-and-cache-objects.aspx[^]

If you DO care if the numbers reset upon an application restart (or if your application is going to be running on multiple servers) then you should take the same approach as previously mentioned but instead of using application state to store your value, use a database system to push/pull the variables.

Hope this helps

-Moarcodeplz


使用ASP创建简单的点击计数器.NET 4.0和C#
http://archive.devnewz.com/2004/0127.html [ http://forums.asp.net/t/1149362.aspx/1?to + create + a + hit + counter + in + asp + net [
Creating a Simple Hit Counter with ASP.NET 4.0 and C#
http://archive.devnewz.com/2004/0127.html[^]
http://forums.asp.net/t/1149362.aspx/1?to+create+a+hit+counter+in+asp+net[^]


这篇关于如何在ASP.NET中进行计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆