PLZ看到我的Global.asax:是什麼betweeen這兩個OnlineUsers方法的區別在Global.asax中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using DataLayer;
using NiceFileExplorer.Classes;
using System.IO;
using System.Text;
using System.Data;
using System.Web.Hosting;
namespace NiceFileExplorer
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Application["OnlineUsers"] = 0;
}
protected void Session_Start(object sender, EventArgs e)
{
Application.Lock();
OnlineUsers.InsertRow(
Session.SessionID,
DateTime.Now, //Session Start Time
DBNull.Value, //Session End Time
true);
//OnlineUsers Is A Table In MS SQL SERVER 2008
//InsertRow Is A StoredProcedure Of OnlineUsers Table Like Below :
// ALTER Procedure [dbo].[sp_OnlineUsers_Insert]
// @Session_ID nvarchar(300),
// @Session_Start datetime,
// @Session_End datetime = NULL,
// @Online bit
//As
//Begin
// Insert Into OnlineUsers
// ([Session_ID],[Session_Start],[Session_End],[Online])
// Values
// (@Session_ID,@Session_Start,@Session_End,@Online)
// Declare @ReferenceID int
// Select @ReferenceID = @@IDENTITY
// Return @ReferenceID
//End
Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
Application.UnLock();
}
protected void Session_End(object sender, EventArgs e)
{
Application.Lock();
OnlineUsers.UpdateRow_Some_Fields_By_SessionID(
Session.SessionID,
DateTime.Now,
false);
//UpdateRow_Some_Fields_By_SessionID Is A StoredProcedure Of OnlineUsers Table Like Below :
// ALTER Procedure [dbo].[sp_OnlineUsers_Update_Some_Fields_By_SessionID]
// @Session_ID nvarchar(300),
// @Session_End datetime,
// @Online bit
//As
//Begin
// Update OnlineUsers
// Set
// [Session_End] = @Session_End,
// [Online] = @Online
// Where
// [Session_ID] = @Session_ID
//End
Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
Application.UnLock();
}
protected void Application_End(object sender, EventArgs e)
{
}
}
}
我必須標籤在我的項目用於顯示OnlineUsers!
1使用:
Application["OnlineUsers"].ToString();
2使用的是:
OnlineUsers.Count_Users().ToString();
//Count_Users Is A StoredProcedure Of OnlineUsers Like Below :
//ALTER Procedure [dbo].[sp_OnlineUsers_Count]
// As
// Begin
// Select
// [Session_ID],
// [Session_Start],
// [Session_End],
// [Online]
// From OnlineUsers
// Where
// [Online] = 1
// Declare @Count int
// Select @Count = @@ROWCOUNT
// Return @Count
// End
有時拉布勒1向我們展示:5
但拉布勒2向我們展示:255
我做了什麼他們錯了嗎?
爲什麼他們之間有很大的區別?
編輯
我在web.config中的sessionState是這樣的:
<sessionState mode="InProc" cookieless="false" timeout="1" />
在此先感謝
真的很感謝關注! PLZ看到我的編輯,之後你會plz給我一些關於Session.IsNewSession的解釋! – MoonLight