zoukankan      html  css  js  c++  java
  • 网站流量统计

    前台:

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>网站浏览统计</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="count" runat="server" Text="Label"></asp:Label>
        </div>
        </form>
    </body>
    </html>

    注:label标签是用来展示网站统计流量的位置的,这个你可以随意放置哦!呵呵

    后台代码:

     long counter = 1;//声明一个计数器变量,并赋初值为1;

        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            Application.Lock();//进行锁定,防止非同步更新
            string countfile = Server.MapPath("count.txt");
            if (File.Exists(countfile))
            {
                StreamReader sReader = new StreamReader(countfile);
                string s;
                long x;
                s = sReader.ReadLine();
                if (s != null)
                {
                    x = Convert.ToInt64(s);
                    counter = x + 1;
                }
                sReader.Close();
            }//end if
            StreamWriter sWriter = new StreamWriter(countfile);
            sWriter.Write((counter.ToString()));//将long类型转换为string类型
            sWriter.Flush();
            sWriter.Close();
            Application.UnLock();

            count.Text = "您是本站第" + counter + "位访客";

    }
  • 相关阅读:
    12.13 Redis缓存面试题精简版
    12.12 Oracle数据库相关面试题精简版(后续继续完善)
    1.131 IDEA2018版本64位激活
    7.11 读《如何阅读一本书》有感
    Linux下source命令详解(转载)
    Scala 随笔
    SparkStreaming实时流式大数据处理实战总结
    转载:hive的一些udaf
    IDEA的一些常见报错
    hive使用UDF函数
  • 原文地址:https://www.cnblogs.com/skyshenwei/p/1651866.html
Copyright © 2011-2022 走看看