asp.net在线人数统计
有人也问了个在线统计的问题,我的见意是这样的:
在Application_Start事件中加入以下代码:
Application.Lock();
Application.["UserCount"]=0;
Application.Unlock();
Session_Start事件中加入以下代码:
Application.Lock();
Application["UserCount']=Int32.Parse(Application["UserCount"].Tostring())+1;
Application.UnLock();
Session_End事件中加入以下代码:
Application.Lock();
Application["UserCount"]=Int32.Parse(Application["UserCount"].Tostring())-1;
Application.UnLock();
在要显示的地方写个函数加入以下代码:
Response.Write(Application["UserCount"].Tostring());
这就OK了
相关文档:
首页:
<%@ 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 ......
ajax 在目前 web 领域已广泛应用,其真正核心只不过是一个封装好了的 js 库。最五花八门的莫过于 asp.net 的控件,我个人认为 ajax 只是一个轻量级的东西,根本没有必要将它写成服务器组件,如 ajax.net、AjaxControlToolkit 等。所以我一直视这些组件为垃圾。。。
以下说明我为什么不认同 ajax 的相关组件: ......
日期转化一
为了达到不同的显示效果有时,我们需要对时间进行转化,默认格式为:2007-01-03 14:33:34 ,要转化为其他格式,要用到DateTime.ToString的方法(String, IFormatProvider),如下所示:
using System;
using System.Globalization;
String format="D";
DateTime date=DataTime,Now;
Response.Write(date.ToS ......
示例一
在Global.asax.cs文件中:
protected void Application_Start(Object sender, EventArgs e)
{
System.Timers.Timer timer1 = new System.Timers.Timer();
&nbs ......
ASP.NET防止SQL注入函数:
using System;
using System.Text.RegularExpressions;
using System.Web;
namespace FSqlKeyWord
......{
/**//**//**//// <summary>
/// SqlKey 的摘要说明。
/// </summary>
public class S ......