مهدی رحیم زاده
شنبه 09 شهریور 1387, 22:23 عصر
سلام
من برای آمار گیری تعداد بازدید توی سایتم توی Global این کدو نوشتم :
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserCount"] = 0;
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
int i = Convert.ToInt32(Application["UserCount"]);
i++;
Application["UserCount"] = i;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
int i = Convert.ToInt32(Application["UserCount"]);
i--;
Application["UserCount"] = i;
Application.UnLock();
}
</script>
اما این کد با هربار Refresh صفحه یکبار اجرا میشه یعنی هر بار که صفحه Refresh میشه به عنوان یک بار بازدید یکی به اون اضافه می کنه . چکار کنم که درست بشه .
ممنون
من برای آمار گیری تعداد بازدید توی سایتم توی Global این کدو نوشتم :
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserCount"] = 0;
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Application.Lock();
int i = Convert.ToInt32(Application["UserCount"]);
i++;
Application["UserCount"] = i;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
int i = Convert.ToInt32(Application["UserCount"]);
i--;
Application["UserCount"] = i;
Application.UnLock();
}
</script>
اما این کد با هربار Refresh صفحه یکبار اجرا میشه یعنی هر بار که صفحه Refresh میشه به عنوان یک بار بازدید یکی به اون اضافه می کنه . چکار کنم که درست بشه .
ممنون