VS2005下实现asp.net在线人数的统计
首先在项目中选择“添加新项”,添加“Global.asax”全局变量文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.IO ;
namespace movie
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class Global : System.Web.HttpApplication
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
Application["conn"]="Server=localhost;database=movie;uid=sa;pwd='zcc';";
Application["user_sessions"] = 0;
Application["counter_num"]=0;
uint count=0;
StreamReader srd;
//取得文件的实际路径
string file_path=Server.MapPath ("counter.txt");
//打开文件进行读取
srd=File.OpenText (file_path);
while(srd.Peek ()!=-1)
{
string str=srd.ReadLine ();
count=UInt32.Parse (str);
}
object obj=count;
Application["counter"]=obj;
srd.Close ();
}
protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock();
Application["user_sessions"] = (int)Application["user_sessions"] + 1;
Application.UnLock();
Application.Lock ();
//数值累加,注意这里使用了装箱(boxing)
uint jishu=0;
jishu=(uint)Application["counter"];
jishu=jishu+1;
object obj=jishu;
Application["counter"]=obj;
//将数据记录写入文件
 
相关文档:
在Web编程过程中,存在着很多安全隐患。比如在以前的ASP版本中,Cookie为访问者和编程者都提供了方便,并没有提供加密的功能。打开IE浏览器,选择“工具”菜单里的“Internet选项”,然后在弹出的对话框里单击“设置”按钮,选择“查看文件”按钮,在弹出的窗口中,就会显示硬盘里 ......
////今天在修改程序的时候发现一个小的问题特记录如下:
//////有时候datetime无法转成string,可以用getdate()直接插入就可以了
string str = "update adaddress set shenhe=" + ck + " ,shentime=getDate() where id=" + uid + "";
/////////////////////////////////////////
以下具体介绍日期怎样转换
DateTime.Now ......
首先看数据库表结构:
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.Htm ......
Page_Load--页面加载事件.
Page.IspostBack判断是否第一次加载。
每次响应服务信息(既客户请求ASP.NET页面-ASPX文件或Web服务-
ASMX文件)就加载一次(执行一次Page_Load)。
加载的时候并不是每次多编译一次代码文件,因为:每一次请求
ASPX文件时并不是多要进行一次编译,而是第一次执 ......