自己找了个不知道是不是微软的计数器,还得连国外,教育网内好麻烦,就在自己搭的.text blog
上面测试了一个小计数器控件,模仿原作者的很方便,挺好用的calendar控件,
<%@ control language="c#" classname="dottextblogcounter" inherits="dottext.web.ui.controls.basecontrol"%>
<%@import namespace="system.data" %>
<%@import namespace="system.data.sqlclient" %>
<%@import namespace="dottext.framework.data"%>
<script runat="server">
// dottextblogcounter created on 4/25/2005 by:
//*daqingshu http://blog.csdn.net/daqingshu
/// <summary>
/// use session or cookie?
/// </summary>
void page_load(object sender, system.eventargs e)
{
string number = "";
string strsql = "";
string conn = dottext.framework.providers.dbprovider.instance().connectionstring;
httpcookie oldcookie = request.cookies["counter"];
if(oldcookie == null)//if cookie exist,do not count
{
httpcookie cookie = new httpcookie("counter");
datetime dtnow = datetime.now;
timespan tsminute = new timespan(0, 1, 0, 0);//cookie expire time 1 hour
cookie.expires = dtnow + tsminute;
response.cookies.add(cookie);
strsql = "update blog_config set pagevisitcount = pagevisitcount + 1";
sqlhelper.executenonquery(conn, commandtype.text, strsql, null);
}
strsql = "select pagevisitcount from blog_config where blogid = " + convert.toint32(currentblog.blogid);
sqldatareader rdr = sqlhelper.executereader(conn, commandtype.text, strsql, null);
if(rdr.read()){
number = rdr[0].tostring();
}
rdr.close();
if(number.length <= 8)
{
for(int i = 8; i >= number.length; –i)
{
number = "0" + number;
}
}
numbertopicture(number);
}
private void numbertopicture(string number)
{
system.web.ui.webcontrols.literal literal1 = new literal();
system.web.ui.webcontrols.literal literal2 = new literal();
literal1.text = "您是第";
phimage.controls.add(literal1);
if(number.length > 0)
{
for(int i = 0; i < number.length; ++i)
{
stringbuilder strimage = new stringbuilder();//maybe i missing the system.text namespace if it doesnt work
strimage.append("~/images/counter/eggblue/");
strimage.append(number[i]);
strimage.append(".gif");
system.web.ui.webcontrols.image image = new system.web.ui.webcontrols.image();
image.id = "image" + i.tostring();
image.imageurl = strimage.tostring();
phimage.controls.add(image);
}
}
literal2.text = "位访客。";
phimage.controls.add(literal2);
}
</script>
<asp:placeholder runat="server" id="phimage"></asp:placeholder>
的确是个很简单很小的功能,还修改了数据库结构,在表blog_config里面
添加pagevisitcount字段,使用的时候,需要修改pagetemplate.ascx文件,在里面添加
<%@ register tagprefix="overflow" tagname="dottextblogcounter" src="~/skins/dottextblogcounter.ascx" %>
合适的位置添加
<overflow:dottextblogcounter id="dottextblogcounter" runat="server"></overflow:dottextblogcounter>
另外得自己找好看的图片